Skip to content

Fixes issue #124 JSON is overwritten if unable to parse the file in DEV#125

Open
Netgator wants to merge 13 commits intojeresig:masterfrom
Netgator:master
Open

Fixes issue #124 JSON is overwritten if unable to parse the file in DEV#125
Netgator wants to merge 13 commits intojeresig:masterfrom
Netgator:master

Conversation

@Netgator
Copy link
Copy Markdown

Fixes issue #124 JSON is overwritten if unable to parse the file in DEV mode.

If locale JSON file exists AND package is in DEV mode AND the locale is undefined (unreadable) - This HALTS ALL execution by throwing an exception which prevents the locale file(s) from being overwritten inadvertently. The issue is when the JSON is invalid (even just missing a comma) the file is automatically overwritten which can cause developers to loose most existing lines from the file and no way to recover...

…le in DEV mode.

If JSON file exists and in DEV mode but the locale is undefined - HALTS ALL execution with an expection to prevent the files from being overwritten.
Comment thread i18n.js Outdated

locale = this.defaultLocale;

if ((this.devMode) && (fs.existsSync(this.locateFile(locale)))) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would this condition would match if the defaultLocale have parsing errors ?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you want this to be over line 331

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code matches (and throws an error) when json is present BUT is (for example) missing one comma... You can test by creating a file with two comments and then remove the comma from the en.json file. Without this code the file is rewritten when a parse error occurs which potentially erases thousands of lines due to a missing comma :-)

This code prevents a json file from being overwritten when it has content but can not be parsed correctly.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think we want the extra line because the problem would occur in ANY language not just the default language...

Netgator and others added 12 commits March 6, 2019 05:35
updated code to make it compatiable with most current air-bnb /QSS eslint rules.
researched syncronis functions and realized that this only applies in DEFV mode - otherwise the files are cached on startup.
Explicit language parameter in query, domain or session must have precedence over "preferred" language present in the "Accept-Language" header.
Optionally pass custom query string parameter
update to make the default extension to be .json rather than .js
Update i18n.js tonprevent crashes
Dependency updates for NODE 22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants