Skip to content

Commit 8bee979

Browse files
authored
Fix attribute selector parsing (#99)
1 parent 3968270 commit 8bee979

File tree

6 files changed

+28
-13
lines changed

6 files changed

+28
-13
lines changed

crx/capo.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crx/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifest_version": 3,
33
"name": "Capo: get your ﹤𝚑𝚎𝚊𝚍﹥ in order",
44
"description": "Visualize the optimal ordering of ﹤𝚑𝚎𝚊𝚍﹥ elements on any web page",
5-
"version": "1.4.8",
5+
"version": "1.4.9",
66
"permissions": [
77
"scripting",
88
"activeTab",

docs/src/lib/capo.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,14 @@ class $33f7359dc421be0c$export$8f8422ac5947a789 {
122122
const attributes = selector.match(/\[([A-Za-z-]+)="([^"]+)"\]/g) || [];
123123
// Set the attributes on the new element
124124
attributes.forEach((attribute)=>{
125-
const [key, value] = attribute.replace("[", "").replace("]", "").split("=");
126-
element.setAttribute(key, value.slice(1, -1));
125+
// Trim square brackets
126+
attribute = attribute.slice(1, -1);
127+
const delimeterPosition = attribute.indexOf("=");
128+
// Everything before the =
129+
const key = attribute.slice(0, delimeterPosition);
130+
// Everything after the =, with quotes trimmed
131+
const value = attribute.slice(delimeterPosition + 1).slice(1, -1);
132+
element.setAttribute(key, value);
127133
});
128134
return element;
129135
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rviscomi/capo.js",
3-
"version": "1.4.8",
3+
"version": "1.4.9",
44
"description": "Get your ﹤𝚑𝚎𝚊𝚍﹥ in order",
55
"author": "Rick Viscomi",
66
"license": "Apache-2.0",

snippet/capo.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,14 @@ class $d410929ede0a2ee4$export$8f8422ac5947a789 {
123123
const attributes = selector.match(/\[([A-Za-z-]+)="([^"]+)"\]/g) || [];
124124
// Set the attributes on the new element
125125
attributes.forEach((attribute)=>{
126-
const [key, value] = attribute.replace("[", "").replace("]", "").split("=");
127-
element.setAttribute(key, value.slice(1, -1));
126+
// Trim square brackets
127+
attribute = attribute.slice(1, -1);
128+
const delimeterPosition = attribute.indexOf("=");
129+
// Everything before the =
130+
const key = attribute.slice(0, delimeterPosition);
131+
// Everything after the =, with quotes trimmed
132+
const value = attribute.slice(delimeterPosition + 1).slice(1, -1);
133+
element.setAttribute(key, value);
128134
});
129135
return element;
130136
}

src/lib/io.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,14 @@ export class IO {
116116

117117
// Set the attributes on the new element
118118
attributes.forEach((attribute) => {
119-
const [key, value] = attribute
120-
.replace("[", "")
121-
.replace("]", "")
122-
.split("=");
123-
element.setAttribute(key, value.slice(1, -1));
119+
// Trim square brackets
120+
attribute = attribute.slice(1, -1);
121+
const delimeterPosition = attribute.indexOf("=");
122+
// Everything before the =
123+
const key = attribute.slice(0, delimeterPosition);
124+
// Everything after the =, with quotes trimmed
125+
const value = attribute.slice(delimeterPosition + 1).slice(1, -1);
126+
element.setAttribute(key, value);
124127
});
125128

126129
return element;

0 commit comments

Comments
 (0)