Socket
Socket
Sign inDemoInstall

i18next-scanner

Package Overview
Dependencies
5
Maintainers
1
Versions
92
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.4.0 to 1.4.1

lib/match-recursive-regexp.js

27

lib/parser.js

@@ -279,8 +279,29 @@ 'use strict';

var _loop = function _loop() {
var options = {};
var full = r[0];
var key = _lodash2.default.trim(r[1], '\'"');
var options = {};
var key = _lodash2.default.trim(r[1]); // Remove leading and trailing whitespace
var firstChar = key[0];
if (_lodash2.default.includes(['\'', '"'], firstChar)) {
// Remove first and last character
key = key.slice(1, -1);
// Replace two consecutive backslashes with a backslash
key = key.replace(/\\\\/g, '\\');
}
// Replace \' with '
// Input: i18n.t('name=\'{{name}}\'')
// Output: { "name='{{name}}'": "name='{{name}}'" }
if (firstChar === '\'') {
key = key.replace(/\\\'/g, '\'');
}
// Replace \" with "
// Input: i18n.t("name=\"{{name}}\"")
// Output: { "name=\"{{name}}\"": "name=\"{{name}}\"" }
if (firstChar === '"') {
key = key.replace(/\\\"/g, '"');
}
var endsWithComma = full[full.length - 1] === ',';
if (endsWithComma) {

@@ -287,0 +308,0 @@ (function () {

2

package.json
{
"name": "i18next-scanner",
"version": "1.4.0",
"version": "1.4.1",
"description": "Scan your code, extract translation keys/values, and merge them into i18n resource files.",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/i18next/i18next-scanner",

@@ -237,8 +237,29 @@ /* eslint no-console: 0 */

while ((r = re.exec(content))) {
const options = {};
const full = r[0];
const key = _.trim(r[1], '\'"');
const options = {};
let key = _.trim(r[1]); // Remove leading and trailing whitespace
const firstChar = key[0];
if (_.includes(['\'', '"'], firstChar)) {
// Remove first and last character
key = key.slice(1, -1);
// Replace two consecutive backslashes with a backslash
key = key.replace(/\\\\/g, '\\');
}
// Replace \' with '
// Input: i18n.t('name=\'{{name}}\'')
// Output: { "name='{{name}}'": "name='{{name}}'" }
if (firstChar === '\'') {
key = key.replace(/\\\'/g, '\'');
}
// Replace \" with "
// Input: i18n.t("name=\"{{name}}\"")
// Output: { "name=\"{{name}}\"": "name=\"{{name}}\"" }
if (firstChar === '"') {
key = key.replace(/\\\"/g, '"');
}
const endsWithComma = (full[full.length - 1] === ',');
if (endsWithComma) {

@@ -245,0 +266,0 @@ const code = matchBalancedParentheses(content.substr(re.lastIndex));

@@ -151,2 +151,32 @@ import fs from 'fs';

test('Replace double backslash with single backslash', (t) => {
const parser = new Parser({
defaultValue: function(lng, ns, key) {
if (lng === 'en') {
return key;
}
return '__NOT_TRANSLATED__';
},
keySeparator: false,
nsSeparator: false
});
const content = fs.readFileSync(path.resolve(__dirname, 'fixtures/escape.js'), 'utf8');
const wanted = {
"en": {
"translation": {
"Primary 'email' activation": "Primary 'email' activation",
"Primary \"email\" activation": "Primary \"email\" activation",
"name='email' value='{{email}}'": "name='email' value='{{email}}'",
"name=\"email\" value=\"{{email}}\"": "name=\"email\" value=\"{{email}}\"",
"name=\"email\" value='{{email}}'": "name=\"email\" value='{{email}}'",
"name='email' value=\"{{email}}\"": "name='email' value=\"{{email}}\"",
}
}
};
parser.parseFuncFromString(content);
t.same(parser.get(), wanted);
t.end();
});
test('Disable nsSeparator', (t) => {

@@ -153,0 +183,0 @@ const parser = new Parser({

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc