<?php

/*
 * Copyright 2011 Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @group markup
 */
class PhabricatorRemarkupRuleDiffusion
  extends PhutilRemarkupRule {

  public function apply($text) {
    return preg_replace_callback(
      '@\br([A-Z]+[a-z0-9]+)\b@',
      array($this, 'markupDiffusionLink'),
      $text);
  }

  public function markupDiffusionLink($matches) {
    return $this->getEngine()->storeText(
      '<a href="/r'.$matches[1].'">r'.$matches[1].'</a>');
  }

}

<?php

/*
 * Copyright 2011 Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @group markup
 */
class PhabricatorRemarkupRuleDiffusion
  extends PhutilRemarkupRule {

  public function apply($text) {
    return preg_replace_callback(
      '@\br([A-Z]+[a-f0-9]+)\b@',
      array($this, 'markupDiffusionLink'),
      $text);
  }

  public function markupDiffusionLink($matches) {
    return $this->getEngine()->storeText(
      '<a href="/r'.$matches[1].'">r'.$matches[1].'</a>');
  }

}

Use a stricter regexp in Diffusion remarkup
Use a stricter regexp in Diffusion remarkup

Summary:
Just minor bookkeeping, but the current regexp is too liberal and
will match things which can't possibly be revision hashes.

Test Plan:
Typed things which should and shouldn't be revision links, they
got handled properly.

Reviewed By: aran
Reviewers: jungejason, tuomaspelkonen, aran
CC: aran
Differential Revision: 185
