Skip to content

Commit

Permalink
fix: do not decode special chractors #240
Browse files Browse the repository at this point in the history
  • Loading branch information
taoqf committed Aug 17, 2023
1 parent 2852d20 commit cdadb13
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/nodes/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export default class HTMLElement extends Node {
return 'null';
}

return JSON.stringify(attr.replace(/"/g, '"'));
return JSON.stringify(attr.replace(/"/g, '"')).replace(/\\t/g, '\t').replace(/\\n/g, '\n').replace(/\\r/g, '\r');
}

/**
Expand Down
13 changes: 13 additions & 0 deletions test/tests/issues/240.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { parse } = require('@test/test-target');

describe('issue 240', function () {
it(`attribute should not changed`, function () {
const html = "<div unchanged='[\npreserve newline\n]'></div>";
const root = parse(html);
const div = root.firstChild
div.toString().should.eql(html);

div.setAttribute("append", "newAttribute");
div.toString().should.eql('<div unchanged="[\npreserve newline\n]" append="newAttribute"></div>');
});
});

0 comments on commit cdadb13

Please sign in to comment.