Skip to content

Commit 9a458eb

Browse files
twskjtwskj
authored andcommitted
fix: html escape bug
1 parent 7d7657e commit 9a458eb

4 files changed

Lines changed: 33 additions & 3 deletions

File tree

CHANGELOG

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
v0.1.1 [Dec 26, 2018]
1+
v0.1.3 [Dec 26, 2018]
2+
- fixed html escape bug
3+
4+
v0.1.2 [Dec 26, 2018]
25
- improve searching performance
36

47
v0.1.1 [Dec 25, 2018]

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 twskj
3+
Copyright (c) 2019 twskj
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

main.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,24 @@ function extractJSONs(str) {
236236
return jsons;
237237
}
238238

239+
var decoder;
240+
function decodeHTML(str, idx) {
241+
if (!decoder) {
242+
decoder = document.createElement("textarea");
243+
}
244+
245+
var i = idx;
246+
for (; i < str.length; i++) {
247+
if (str[i] === ';') {
248+
break;
249+
}
250+
}
251+
252+
var length = i - idx + 1;
253+
decoder.innerHTML = str.substr(idx, length);
254+
return [decoder.innerText, length];
255+
}
256+
239257
function computeStartEnd(html, prefix, text) {
240258
var start = -1;
241259
var tag = false;
@@ -265,6 +283,15 @@ function computeStartEnd(html, prefix, text) {
265283
continue;
266284
}
267285

286+
if (ch === '&') {
287+
var [ch, tokenLength] = decodeHTML(html, current_idx);
288+
current_idx += tokenLength - 1;
289+
290+
if (whitespace.has(ch)) {
291+
continue;
292+
}
293+
}
294+
268295
if (ch === prefix[runner]) {
269296
while (runner < prefix.length) {
270297
runner++;

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Jipy",
33
"short_name": "Jipy",
4-
"version": "0.1.2",
4+
"version": "0.1.3",
55
"description": "Format JSON In Place. Anywhere!",
66
"author": "twskj",
77
"browser_action": {

0 commit comments

Comments
 (0)