Skip to content

Commit

Permalink
update html-parse-stringify to fix uppercase elements in Trans compon…
Browse files Browse the repository at this point in the history
…ent, fixes #1304
  • Loading branch information
adrai committed Apr 28, 2021
1 parent 69e263c commit 4b89b47
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 11.8.14

- update html-parse-stringify to fix uppercase elements in Trans component [1304](https://github.com/i18next/react-i18next/issues/1304)

### 11.8.13

- Replace html-parse-stringify2 with html-parse-stringify [1283](https://github.com/i18next/react-i18next/pull/1283) to prevent [CVE-2021-23346](https://github.com/i18next/react-i18next/issues/1275)
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"dependencies": {
"@babel/runtime": "^7.13.6",
"html-parse-stringify": "^3.0.0"
"html-parse-stringify": "^3.0.1"
},
"devDependencies": {
"@babel/cli": "^7.2.3",
Expand Down
2 changes: 1 addition & 1 deletion react-i18next.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
},
i = n.match(/<\/?([^\s]+?)[/\s>]/);

if (i && (r.name = i[1], (voidElements[i[1].toLowerCase()] || "/" === n.charAt(n.length - 2)) && (r.voidElement = !0), r.name.startsWith("!--"))) {
if (i && (r.name = i[1], (voidElements[i[1]] || "/" === n.charAt(n.length - 2)) && (r.voidElement = !0), r.name.startsWith("!--"))) {
var s = n.indexOf("--\x3e");
return {
type: "comment",
Expand Down
2 changes: 1 addition & 1 deletion react-i18next.min.js

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions test/trans.render.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,3 +475,51 @@ describe('trans should work with misleading overloaded empty elements in compone
`);
});
});

describe('trans should work with lowercase elements in components', () => {
const TestComponent = () => (
<Trans
i18nKey="someKeyWithLowercaseComp"
defaults="click <whatever>here</whatever> for more"
components={{ whatever: <a href="/foo">dummy</a> }}
/>
);
it('should render translated string', () => {
const { container } = render(<TestComponent />);
expect(container.firstChild).toMatchInlineSnapshot(`
<div>
click
<a
href="/foo"
>
here
</a>
for more
</div>
`);
});
});

describe('trans should work with uppercase elements in components', () => {
const TestComponent = () => (
<Trans
i18nKey="someKeyWithUppercaseComp"
defaults="click <Link>here</Link> for more"
components={{ Link: <a href="/foo">dummy</a> }}
/>
);
it('should render translated string', () => {
const { container } = render(<TestComponent />);
expect(container.firstChild).toMatchInlineSnapshot(`
<div>
click
<a
href="/foo"
>
here
</a>
for more
</div>
`);
});
});

0 comments on commit 4b89b47

Please sign in to comment.