Skip to content

Commit cdadb13

Browse files
committed
fix: do not decode special chractors #240
1 parent 2852d20 commit cdadb13

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/nodes/html.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export default class HTMLElement extends Node {
158158
return 'null';
159159
}
160160

161-
return JSON.stringify(attr.replace(/"/g, '"'));
161+
return JSON.stringify(attr.replace(/"/g, '"')).replace(/\\t/g, '\t').replace(/\\n/g, '\n').replace(/\\r/g, '\r');
162162
}
163163

164164
/**

test/tests/issues/240.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const { parse } = require('@test/test-target');
2+
3+
describe('issue 240', function () {
4+
it(`attribute should not changed`, function () {
5+
const html = "<div unchanged='[\npreserve newline\n]'></div>";
6+
const root = parse(html);
7+
const div = root.firstChild
8+
div.toString().should.eql(html);
9+
10+
div.setAttribute("append", "newAttribute");
11+
div.toString().should.eql('<div unchanged="[\npreserve newline\n]" append="newAttribute"></div>');
12+
});
13+
});

0 commit comments

Comments
 (0)