Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

undefined Error when string has no closing tag #451

Closed
dguillamot opened this issue Jun 7, 2018 · 7 comments
Closed

undefined Error when string has no closing tag #451

dguillamot opened this issue Jun 7, 2018 · 7 comments
Labels

Comments

@dguillamot
Copy link

dguillamot commented Jun 7, 2018

An error is thrown from Trans.js line 78 (react-i18next.js line 1064) when the inputted string is just a single opening XML element.

Our string was 'This is a test string'.. However, translators accidentally surrounded this with angle brackets. making the string <This is a test string>.

The result was a crash in Trans.js at line 78 in renderNodes(). 'Cannot read property 'content' of undefined' at this line:
const interpolated = i18n.services.interpolator.interpolate(node.children[0].content, child, i18n.language);

So, if the inputted string does not have a valid closing xml tag (in our case the entire string was one single opening xml tag), node.children[0] is, naturally, undefined as there are no children to that node.

Should Trans.js check for null node.children here, or higher up in the pipeline?

@jamuhl
Copy link
Member

jamuhl commented Jun 7, 2018

would you mind providing a PR or at least a failing testcase for this?

@dguillamot
Copy link
Author

@jamuhl Yes, if I have time on the weekend I will take a crack at it.

@jamuhl
Copy link
Member

jamuhl commented Jun 7, 2018

i guess the error is caused here: https://github.com/i18next/react-i18next/blob/master/src/Trans.js#L56

evtl. doing a try catch around the parse and log an error on catch + fallback to unparsed value might be sufficient fix...

@jamuhl jamuhl added the bug label Jun 26, 2018
@isaachinman
Copy link
Contributor

@jamuhl Is this fixed, or would you like a PR for it?

@jamuhl
Copy link
Member

jamuhl commented Nov 14, 2018

not yet fixed...was to low on my personal prio list...feel free to create a PR so this gets finally closed.

@isaachinman
Copy link
Contributor

@dguillamot It's been several months since your offer, do you want to contribute to this library, or shall we take it from here?

@jamuhl
Copy link
Member

jamuhl commented Dec 31, 2018

looks like this got solved by other changes already - at least that code part was removed (changed heavily) and newly added tests do not show any issue for those invalid html tags from translations.

@jamuhl jamuhl closed this as completed Dec 31, 2018
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants