From 0b17136d965ddc602a5a0176b538bdb0a47f4d12 Mon Sep 17 00:00:00 2001 From: alexwl Date: Fri, 8 Feb 2019 00:34:54 +0300 Subject: Fix search for '.' and '..' identifiers --- javascript/app/utils/api-urls.js | 21 ++++++++++++++++++--- javascript/app/utils/language-extensions.js | 2 +- 2 files changed, 19 insertions(+), 4 deletions(-) (limited to 'javascript/app') diff --git a/javascript/app/utils/api-urls.js b/javascript/app/utils/api-urls.js index da8fdcb..d90c68a 100644 --- a/javascript/app/utils/api-urls.js +++ b/javascript/app/utils/api-urls.js @@ -1,5 +1,20 @@ import config from '../config/environment'; +// "." and ".." is a special case because of the Path Segment Normalization: +// https://tools.ietf.org/html/rfc3986#section-6.2.2.3 +// The segments “..” and “.” can be removed from a URL by a browser. +// https://stackoverflow.com/questions/3856693/a-url-resource-that-is-a-dot-2e +function fixDots(string) { + if(string === ".") { + return "%20%2E"; + } + else if(string === "..") { + return "%20%2E%2E"; + } else { + return string.replace(/\./g, '%2E'); + } +} + export const urls = { packageInfoUrl : function(packageId) { return config.APP.staticUrlPrefix+"/"+packageId+"/"+config.APP.haskellCodeExplorerDirectory+"/packageInfo.json"; @@ -12,7 +27,7 @@ export const urls = { }, packagesUrl : config.APP.apiUrlPrefix + "/packages", identifierDefinitionSiteUrl : function(packageId,moduleName,componentId,entity,name) { - return config.APP.apiUrlPrefix + "/definitionSite/" + packageId+"/"+componentId+"/"+moduleName+"/"+entity+"/"+encodeURIComponent(name).replace(/\./g, '%2E'); + return config.APP.apiUrlPrefix + "/definitionSite/" + packageId+"/"+componentId+"/"+moduleName+"/"+entity+"/"+fixDots(encodeURIComponent(name)); }, modulePathUrl : function (packageId,moduleName,componentId) { return config.APP.apiUrlPrefix + "/modulePath/"+packageId+"/"+componentId+"/"+moduleName; @@ -24,12 +39,12 @@ export const urls = { return config.APP.apiUrlPrefix + "/references/"+packageId+"/"+encodeURIComponent(externalId); }, identifierSearchUrl : function (packageId,query) { - return config.APP.apiUrlPrefix + "/identifiers/"+packageId+"/"+encodeURIComponent(query).replace(/\./g, '%2E'); + return config.APP.apiUrlPrefix + "/identifiers/"+packageId+"/"+fixDots(encodeURIComponent(query)); }, globalReferencesUrl : function (externalId) { return config.APP.apiUrlPrefix + "/globalReferences/"+encodeURIComponent(externalId); }, globalIdentifiersUrl : function (query) { - return config.APP.apiUrlPrefix + "/globalIdentifiers/"+encodeURIComponent(query).replace(/\./g, '%2E'); + return config.APP.apiUrlPrefix + "/globalIdentifiers/"+fixDots(encodeURIComponent(query)); } } diff --git a/javascript/app/utils/language-extensions.js b/javascript/app/utils/language-extensions.js index f4f23bd..bee90b6 100644 --- a/javascript/app/utils/language-extensions.js +++ b/javascript/app/utils/language-extensions.js @@ -506,7 +506,7 @@ function addLinksToLanguageExtensionsDocs(string) { return match; } }); -}; +} export { addLinksToLanguageExtensionsDocs -- cgit v1.2.3