-
-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix escaped characters in translations #569
Changes from all commits
3ff83d5
aa4a78f
4105d05
e66298e
08865e7
059771b
33cfaa6
cda5d7d
e14dbd6
3fd2ad1
54a6e3f
348b4bb
9a3c712
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,20 +14,48 @@ test('that translation files are valid json', t => { | |
jsonFiles.map(name), | ||
'each xml file has a corresponding json file' | ||
) | ||
const testFile = file => { | ||
let json = null | ||
try { | ||
json = require(file) | ||
} catch (e) { | ||
console.error(e.message) | ||
return false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. First test makes sure the file is valid json. |
||
} | ||
return Object.keys(json).every(k1 => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For every resource .. |
||
const v1 = json[k1] | ||
return Object.keys(v1).every(k2 => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. .. every key of that resource (e.g. |
||
const v2 = v1[k2] | ||
if (typeof v2 !== 'string') { | ||
console.error( | ||
`> ${JSON.stringify(v2)} not a string (${file} -> ${k1} -> ${k2})` | ||
) | ||
return false | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be a string .. |
||
function testString (str) { | ||
const regex = new RegExp(str, 'g') | ||
const match = regex.exec(v2) | ||
if (match) { | ||
console.error(`> ${JSON.stringify(v2)} contains ${str} (${file} -> ${k1} -> ${k2}) (index: ${match.index})`) | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
if (!testString('\\\\n')) return false | ||
if (!testString("\\\\'")) return false | ||
if (!testString('\\\\\\"')) return false | ||
if (!testString('\\\\')) return false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And it shouldn't contain these. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could probably refactor this into one There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's fine with multiple returns to me |
||
|
||
return true | ||
}) | ||
}) | ||
} | ||
t.is( | ||
jsonFiles.every(f => { | ||
let ok = false | ||
const fullPath = path.join(dir, f) | ||
try { | ||
require(fullPath) | ||
ok = true | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
return ok | ||
}), | ||
jsonFiles.every(f => testFile(path.join(dir, f))), | ||
true, | ||
'json is valid' | ||
'valid json and valid strings' | ||
) | ||
t.end() | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't have a new line in the original