From e1da1d86d68021f7e69191e72f27e4293d2a0fe4 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 29 Oct 2019 09:37:22 -0700 Subject: [PATCH] Trim and URI encode symbol names before building URIs from them Summary: Fixes T13437. This URI construction was just missing URI encoding. Also, trim the symbol because my test case ended up catching "#define\n" as symbol text. Test Plan: - Configured a repository to have PHP symbols. - Touched a ".php" file with "#define" in it. - Diffed the change. - Command-clicked "#define" in the UI, in Safari/MacOS, to jump to the definition. - Before: taken to a nonsense page where "#define" became an anchor. - After: taken to symbol search for "#define". Maniphest Tasks: T13437 Differential Revision: https://secure.phabricator.com/D20876 --- resources/celerity/map.php | 18 +++++++++--------- .../repository/repository-crossreference.js | 11 ++++++++++- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/resources/celerity/map.php b/resources/celerity/map.php index 0e53737aaf..19d74a3f52 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -12,7 +12,7 @@ return array( 'core.pkg.css' => '686ae87c', 'core.pkg.js' => '6e5c894f', 'differential.pkg.css' => '607c84be', - 'differential.pkg.js' => 'a0212a0b', + 'differential.pkg.js' => '1b97518d', 'diffusion.pkg.css' => '42c75c37', 'diffusion.pkg.js' => 'a98c0bf7', 'maniphest.pkg.css' => '35995d6d', @@ -428,7 +428,7 @@ return array( 'rsrc/js/application/releeph/releeph-preview-branch.js' => '75184d68', 'rsrc/js/application/releeph/releeph-request-state-change.js' => '9f081f05', 'rsrc/js/application/releeph/releeph-request-typeahead.js' => 'aa3a100c', - 'rsrc/js/application/repository/repository-crossreference.js' => 'c15122b4', + 'rsrc/js/application/repository/repository-crossreference.js' => '1c95ea63', 'rsrc/js/application/search/behavior-reorder-profile-menu-items.js' => 'e5bdb730', 'rsrc/js/application/search/behavior-reorder-queries.js' => 'b86f297f', 'rsrc/js/application/transactions/behavior-comment-actions.js' => '4dffaeb2', @@ -682,7 +682,7 @@ return array( 'javelin-behavior-reorder-applications' => 'aa371860', 'javelin-behavior-reorder-columns' => '8ac32fd9', 'javelin-behavior-reorder-profile-menu-items' => 'e5bdb730', - 'javelin-behavior-repository-crossreference' => 'c15122b4', + 'javelin-behavior-repository-crossreference' => '1c95ea63', 'javelin-behavior-scrollbar' => '92388bae', 'javelin-behavior-search-reorder-queries' => 'b86f297f', 'javelin-behavior-select-content' => 'e8240b50', @@ -1034,6 +1034,12 @@ return array( 'javelin-install', 'javelin-util', ), + '1c95ea63' => array( + 'javelin-behavior', + 'javelin-dom', + 'javelin-stratcom', + 'javelin-uri', + ), '1cab0e9a' => array( 'javelin-behavior', 'javelin-dom', @@ -1977,12 +1983,6 @@ return array( 'c03f2fb4' => array( 'javelin-install', ), - 'c15122b4' => array( - 'javelin-behavior', - 'javelin-dom', - 'javelin-stratcom', - 'javelin-uri', - ), 'c2c500a7' => array( 'javelin-install', 'javelin-dom', diff --git a/webroot/rsrc/js/application/repository/repository-crossreference.js b/webroot/rsrc/js/application/repository/repository-crossreference.js index d6ff2a06aa..ba522d5b47 100644 --- a/webroot/rsrc/js/application/repository/repository-crossreference.js +++ b/webroot/rsrc/js/application/repository/repository-crossreference.js @@ -152,7 +152,16 @@ JX.behavior('repository-crossreference', function(config, statics) { query.char = char; } - var uri = JX.$U('/diffusion/symbol/' + symbol + '/'); + var uri_symbol = symbol; + + // In some cases, lexers may include whitespace in symbol tags. Trim it, + // since symbols with semantic whitespace aren't supported. + uri_symbol = uri_symbol.trim(); + + // See T13437. Symbols like "#define" need to be encoded. + uri_symbol = encodeURIComponent(uri_symbol); + + var uri = JX.$U('/diffusion/symbol/' + uri_symbol + '/'); uri.addQueryParams(query); window.open(uri.toString());