Skip to content

Commit

Permalink
Merge pull request #1826 from CondeNast/utf8-encoding
Browse files Browse the repository at this point in the history
chore: use utf8 charset when encoding entities
  • Loading branch information
supeluri authored Dec 13, 2024
2 parents d5e59b8 + 35525cd commit 6cf5d51
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/@atjson/renderer-html/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default class HTMLRenderer extends Renderer {
}

text(text: string) {
return entities.encode(text);
return entities.encode(text, { mode: entities.EncodingMode.UTF8 });
}

htmlAttributes(attributes: {
Expand Down
38 changes: 38 additions & 0 deletions packages/@atjson/renderer-html/test/encoding.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import Renderer from "../src";

describe("encoding entities", () => {
test("Japanese", () => {
let doc = {
text: "\uFFFC同性の両親",
blocks: [
{
attributes: {},
id: "B00000000",
parents: [],
selfClosing: false,
type: "paragraph",
},
],
marks: [],
};

expect(Renderer.render(doc)).toEqual("<p>同性の両親</p>");
});
test("HTML reserved entities", () => {
let doc = {
text: "\uFFFC<>&",
blocks: [
{
attributes: {},
id: "B00000000",
parents: [],
selfClosing: false,
type: "paragraph",
},
],
marks: [],
};

expect(Renderer.render(doc)).toEqual("<p>&lt;&gt;&amp;</p>");
});
});

0 comments on commit 6cf5d51

Please sign in to comment.