New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

jsxgettext

Package Overview
Dependencies
Maintainers
6
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsxgettext - npm Package Compare versions

Comparing version 0.3.2 to 0.3.3

23

lib/jsxgettext.js

@@ -166,3 +166,3 @@ /* jshint node: true, undef: true */

Object.keys(jadeSources).forEach(function (filename) {
jadeSources[filename] = parseJade(jadeSources[filename]);
jadeSources[filename] = parseJade(jadeSources[filename], options);
});

@@ -237,2 +237,8 @@ return gen(jadeSources, options);

// From MDN:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Using_Special_Characters
function escapeRegExp(string){
return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
}
function parseJade(str, options) {

@@ -247,6 +253,13 @@ options = options || {};

var gettextRegexPrefix = '(?:gettext';
if (options.keyword) {
gettextRegexPrefix += '|' + escapeRegExp(options.keyword);
}
gettextRegexPrefix += ')';
var gettexRegex = new RegExp(gettextRegexPrefix + '(?:\\(\"[^"]+\"|\\(\'[^\']+\')', 'gi');
function extractGettext(str) {
if (typeof(str) !== 'string') return '';
var tmp = str.match(/gettext\(\"[^"]+\"/ig) || [];
tmp = tmp.concat(str.match(/gettext\(\'[^']+\'/ig) || []);
var tmp = str.match(gettexRegex) || [];
return tmp.map(function(t) {

@@ -275,3 +288,3 @@ return t + ')';

break;
case 'text':
case 'text':
case 'code':

@@ -340,3 +353,3 @@ tmp = extractGettext(token.val);

str = str.substring(match.index + match[0].length);
// Translate the match into an appropriate chunk of javascript.

@@ -343,0 +356,0 @@ if (match.type == 'comment') {

@@ -5,3 +5,3 @@ {

"description": "Extract gettext calls from JavaScript and EJS files",
"version": "0.3.2",
"version": "0.3.3",
"repository": {

@@ -18,3 +18,3 @@ "type": "git",

"estraverse": "1.1.2-1",
"gettext-parser": "0.1.8",
"gettext-parser": "0.1.10",
"nomnom": "1.5.2",

@@ -21,0 +21,0 @@ "jade": "0.30.0"

@@ -5,3 +5,3 @@ var fs = require('fs');

exports['test jade'] = function (assert, cb) {
exports['test parsing'] = function (assert, cb) {
// check that files with leading hash parse

@@ -11,13 +11,32 @@ var inputFilename = path.join(__dirname, 'inputs', 'second_attribute.jade');

var opts = {},
var opts = {keyword: '_'},
sources = {'inputs/second_attribute.jade': source},
result = jsxgettext.generateFromJade(sources, 'inputs/second_attribute.jade', opts);
result = jsxgettext.generateFromJade(sources, opts);
assert.equal(typeof result, 'string', 'result is a string');
assert.ok(result.length > 1, 'result is not empty');
assert.ok(result.indexOf('msgid "bar"') > -1, 'bar is found');
assert.ok(result.indexOf('msgid "same-lime"') > -1, 'same-lime is found');
assert.ok(result.indexOf('msgid "in text"') > -1, 'in text is found');
assert.ok(result.indexOf('msgid "foobar"') > -1, 'foobar is found');
assert.ok(result.indexOf('msgid "underscored"') > -1, 'underscored is found');
cb();
});
};
exports['test regexp escaping'] = function(assert, cb) {
// check that files with leading hash parse
var inputFilename = path.join(__dirname, 'inputs', 'second_attribute.jade');
fs.readFile(inputFilename, "utf8", function (err, source) {
// if keyword is not escaped, this will throw an exception
var opts = {keyword: 'foo)bar'},
sources = {'inputs/second_attribute.jade': source},
result = jsxgettext.generateFromJade(sources, opts);
// ..and won't reach to here.
assert.ok(true, 'regexp should not throw');
cb();
});
};
if (module == require.main) require('test').run(exports);

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc