You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@annotator.apache.org by ge...@apache.org on 2020/04/03 11:53:22 UTC
[incubator-annotator] 07/09: Percent-encode parentheses in
stringify()
This is an automated email from the ASF dual-hosted git repository.
gerben pushed a commit to branch fragment-tests
in repository https://gitbox.apache.org/repos/asf/incubator-annotator.git
commit 01dab3147e2e7884ea9eef3af207b7f32fbb1955
Author: Gerben <ge...@treora.com>
AuthorDate: Thu Apr 2 21:33:45 2020 +0200
Percent-encode parentheses in stringify()
---
packages/fragment-identifier/src/index.js | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/packages/fragment-identifier/src/index.js b/packages/fragment-identifier/src/index.js
index 0ba2e4d..39513ae 100644
--- a/packages/fragment-identifier/src/index.js
+++ b/packages/fragment-identifier/src/index.js
@@ -31,10 +31,10 @@ export function stringify(resource) {
let value = resource[key];
if (value instanceof Object) value = value.valueOf();
if (value instanceof Object) {
- value = stringify(value);
- return `${encodeURIComponent(key)}=${value}`;
+ return `${encode(key)}=${stringify(value)}`;
+ } else {
+ return `${encode(key)}=${encode(value)}`;
}
- return [key, value].map(encodeURIComponent).join('=');
})
.join(',');
@@ -42,3 +42,9 @@ export function stringify(resource) {
if (/State$/.test(resource.type)) return `state(${data})`;
throw new TypeError('Resource must be a Selector or State');
}
+
+function encode(string) {
+ return encodeURIComponent(string)
+ .replace(/\(/g, '%28')
+ .replace(/\)/g, '%29')
+}