summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorskaegi <simon_kaegi@ca.ibm.com>2013-10-16 15:05:15 -0400
committerskaegi <simon_kaegi@ca.ibm.com>2013-10-16 15:05:15 -0400
commit36f680da4e91d4bd93a9abf3e47bdd7dfac51cd9 (patch)
tree92aaf6d55fc006507f80aefea895c33eaf90aa41
parent71fa7b6a22ba895b63822fb7e08d87daf1642a5e (diff)
downloadorg.eclipse.orion.client-origin/ggayedTestBranch.zip
org.eclipse.orion.client-origin/ggayedTestBranch.tar.gz
org.eclipse.orion.client-origin/ggayedTestBranch.tar.bz2
Bug 419627 - URITemplate resevered expansion must ignore percent encoded literalsorigin/ggayedTestBranch
-rw-r--r--bundles/org.eclipse.orion.client.core/web/orion/URITemplate.js9
-rw-r--r--bundles/org.eclipse.orion.client.ui/web/js-tests/URITemplate/testcase.js6
2 files changed, 12 insertions, 3 deletions
diff --git a/bundles/org.eclipse.orion.client.core/web/orion/URITemplate.js b/bundles/org.eclipse.orion.client.core/web/orion/URITemplate.js
index a398e57..d4d020a 100644
--- a/bundles/org.eclipse.orion.client.core/web/orion/URITemplate.js
+++ b/bundles/org.eclipse.orion.client.core/web/orion/URITemplate.js
@@ -26,6 +26,7 @@ define(function(){
};
var VARSPEC_REGEXP = /^((?:(?:[a-zA-Z0-9_])|(?:%[0-9A-F][0-9A-F]))(?:(?:[a-zA-Z0-9_.])|(?:%[0-9A-F][0-9A-F]))*)(?:(\*)|:([0-9]+))?$/;
+ var PCT_ENCODED_G = /%25[0-9A-F][0-9A-F]/g;
function Literal(text) {
this._text = text;
@@ -37,6 +38,10 @@ define(function(){
}
};
+ function decodePercent(str) {
+ return str.replace("%25", "%");
+ }
+
function encodeString(value, encoding) {
if (encoding === "U") { //$NON-NLS-0$
return encodeURIComponent(value).replace(/[!'()*]/g, function(str) {
@@ -44,10 +49,10 @@ define(function(){
});
}
if (encoding === "U+R") { //$NON-NLS-0$
- return encodeURI(value).replace(/%5B/g, '[').replace(/%5D/g, ']'); //$NON-NLS-1$ //$NON-NLS-0$
+ return encodeURI(value).replace(/%5B/g, '[').replace(/%5D/g, ']').replace(PCT_ENCODED_G, decodePercent); //$NON-NLS-1$ //$NON-NLS-0$
}
if (encoding === "U+R-,") { //$NON-NLS-0$
- return encodeURI(value).replace(/%5B/g, '[').replace(/%5D/g, ']').replace(/,/g, '%2C'); //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-0$
+ return encodeURI(value).replace(/%5B/g, '[').replace(/%5D/g, ']').replace(PCT_ENCODED_G, decodePercent).replace(/,/g, '%2C'); //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-0$
}
throw new Error("Unknown allowed character set: " + encoding);
}
diff --git a/bundles/org.eclipse.orion.client.ui/web/js-tests/URITemplate/testcase.js b/bundles/org.eclipse.orion.client.ui/web/js-tests/URITemplate/testcase.js
index b434f93..4e80f83 100644
--- a/bundles/org.eclipse.orion.client.ui/web/js-tests/URITemplate/testcase.js
+++ b/bundles/org.eclipse.orion.client.ui/web/js-tests/URITemplate/testcase.js
@@ -30,7 +30,8 @@ define(["orion/assert", "orion/URITemplate"], function(assert, URITemplate) {
y: "768",
empty: "",
empty_keys: {},
- undef: null
+ undef: null,
+ encodedpct: "%25%A2"
};
tests.testLiteralTemplate = function() {
@@ -55,6 +56,7 @@ define(["orion/assert", "orion/URITemplate"], function(assert, URITemplate) {
assert.equal(new URITemplate("{list*}").expand(variables), "red,green,blue");
assert.equal(new URITemplate("{keys}").expand(variables), "semi,%3B,dot,.,comma,%2C");
assert.equal(new URITemplate("{keys*}").expand(variables), "semi=%3B,dot=.,comma=%2C");
+ assert.equal(new URITemplate("{encodedpct}").expand(variables), "%2525%25A2");
};
tests.testReservedExpansion = function() {
@@ -75,6 +77,7 @@ define(["orion/assert", "orion/URITemplate"], function(assert, URITemplate) {
assert.equal(new URITemplate("{+list*}").expand(variables), "red,green,blue");
assert.equal(new URITemplate("{+keys}").expand(variables), "semi,;,dot,.,comma,,");
assert.equal(new URITemplate("{+keys*}").expand(variables), "semi=;,dot=.,comma=,");
+ assert.equal(new URITemplate("{+encodedpct}").expand(variables), "%25%A2");
};
tests.testCommaReservedExpansion = function() {
@@ -95,6 +98,7 @@ define(["orion/assert", "orion/URITemplate"], function(assert, URITemplate) {
assert.equal(new URITemplate("{,list*}").expand(variables), "red,green,blue");
assert.equal(new URITemplate("{,keys}").expand(variables), "semi,;,dot,.,comma,%2C");
assert.equal(new URITemplate("{,keys*}").expand(variables), "semi=;,dot=.,comma=%2C");
+ assert.equal(new URITemplate("{,encodedpct}").expand(variables), "%25%A2");
};
return tests;
});