Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/editor/PhabricatorEditorURIEngine.php
| Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | final class PhabricatorEditorURIEngine | ||||
| } | } | ||||
| public function validatePattern() { | public function validatePattern() { | ||||
| $this->getRawURITokens(); | $this->getRawURITokens(); | ||||
| return true; | return true; | ||||
| } | } | ||||
| public function getURIForPath($path, $line) { | public function getURIForPath($path, $line) { | ||||
| $tokens = $this->getURITokensForRepository(); | $tokens = $this->getURITokensForRepository($path); | ||||
| $variables = array( | $variables = array( | ||||
| 'f' => $this->escapeToken($path), | 'f' => $this->escapeToken($path), | ||||
| 'l' => $this->escapeToken($line), | 'l' => $this->escapeToken($line), | ||||
| ); | ); | ||||
| $tokens = $this->newTokensWithVariables($tokens, $variables); | $tokens = $this->newTokensWithVariables($tokens, $variables); | ||||
| return $this->newStringFromTokens($tokens); | return $this->newStringFromTokens($tokens); | ||||
| } | } | ||||
| public function getURITokensForRepository() { | public function getURITokensForPath($path) { | ||||
| if (!$this->repositoryTokens) { | $tokens = $this->getURITokensForRepository($path); | ||||
| $this->repositoryTokens = $this->newURITokensForRepository(); | |||||
| } | |||||
| return $this->repositoryTokens; | $variables = array( | ||||
| 'f' => $this->escapeToken($path), | |||||
| ); | |||||
| return $this->newTokensWithVariables($tokens, $variables); | |||||
| } | } | ||||
| public static function getVariableDefinitions() { | public static function getVariableDefinitions() { | ||||
| return array( | return array( | ||||
| 'f' => array( | 'f' => array( | ||||
| 'name' => pht('File Name'), | 'name' => pht('File Name'), | ||||
| 'example' => pht('path/to/source.c'), | 'example' => pht('path/to/source.c'), | ||||
| ), | ), | ||||
| Show All 19 Lines | return array( | ||||
| ), | ), | ||||
| '%' => array( | '%' => array( | ||||
| 'name' => pht('Literal Percent Symbol'), | 'name' => pht('Literal Percent Symbol'), | ||||
| 'example' => '%', | 'example' => '%', | ||||
| ), | ), | ||||
| ); | ); | ||||
| } | } | ||||
| private function getURITokensForRepository() { | |||||
| if (!$this->repositoryTokens) { | |||||
| $this->repositoryTokens = $this->newURITokensForRepository(); | |||||
| } | |||||
| return $this->repositoryTokens; | |||||
| } | |||||
| private function newURITokensForRepository() { | private function newURITokensForRepository() { | ||||
| $tokens = $this->getRawURITokens(); | $tokens = $this->getRawURITokens(); | ||||
| $repository = $this->getRepository(); | $repository = $this->getRepository(); | ||||
| if (!$repository) { | if (!$repository) { | ||||
| throw new PhutilInvalidStateException('setRepository'); | throw new PhutilInvalidStateException('setRepository'); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | foreach ($tokens as $key => $token) { | ||||
| $tokens[$key]['value'] = | $tokens[$key]['value'] = | ||||
| $tokens[$last_literal]['value'].$token['value']; | $tokens[$last_literal]['value'].$token['value']; | ||||
| unset($tokens[$last_literal]); | unset($tokens[$last_literal]); | ||||
| } | } | ||||
| $last_literal = $key; | $last_literal = $key; | ||||
| } | } | ||||
| $tokens = array_values($tokens); | |||||
| return $tokens; | return $tokens; | ||||
| } | } | ||||
| private function escapeToken($token) { | private function escapeToken($token) { | ||||
| // Paths are user controlled, so a clever user could potentially make | // Paths are user controlled, so a clever user could potentially make | ||||
| // editor links do surprising things with paths containing "/../". | // editor links do surprising things with paths containing "/../". | ||||
| // Find anything that looks like "/../" and mangle it. | // Find anything that looks like "/../" and mangle it. | ||||
| ▲ Show 20 Lines • Show All 85 Lines • Show Last 20 Lines | |||||