Socket
Socket
Sign inDemoInstall

rewire

Package Overview
Dependencies
0
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.1 to 1.0.2

3

CHANGELOG.md
##Changelog
###v1.0.2
- Improved strict mode detection
###v1.0.1

@@ -4,0 +7,0 @@ - Fixed crash when a global module has been used in the browser

4

lib/detectStrictMode.js

@@ -5,9 +5,9 @@ /**

*
* @param {!String} src
* @param {String} src
* @return {Boolean}
*/
function detectStrictMode(src) {
return (/^\s*"use strict";/g).test(src);
return (/^\s*(?:"use strict"|'use strict')[ \t]*(?:[\r\n]|;)/g).test(src);
}
module.exports = detectStrictMode;
{
"name" : "rewire",
"version" : "1.0.1",
"version" : "1.0.2",
"description" : "Dependency injection for node.js applications",

@@ -5,0 +5,0 @@ "keywords" : [

@@ -5,7 +5,17 @@ var expect = require("expect.js"),

describe("detectStrictMode", function () {
it("should detect \"use strict\"; at the beginning of a string and ignore all whitespace before", function () {
it("should detect all valid uses of \"use strict\";", function () {
expect(detectStrictMode('"use strict";')).to.be(true);
expect(detectStrictMode(' "use strict";')).to.be(true);
expect(detectStrictMode(' \n "use strict";')).to.be(true);
expect(detectStrictMode("'use strict';")).to.be(true);
expect(detectStrictMode(' "use strict";')).to.be(true);
expect(detectStrictMode('\n"use strict";')).to.be(true);
expect(detectStrictMode('\r\n"use strict";')).to.be(true);
expect(detectStrictMode('"use strict"\r\n')).to.be(true);
expect(detectStrictMode('"use strict" ; test();')).to.be(true);
});
it("should not detect invalid uses of \"use strict\";", function () {
expect(detectStrictMode('" use strict ";')).to.be(false);
expect(detectStrictMode('"use strict".replace("use", "fail");')).to.be(false);
expect(detectStrictMode('"use strict" .replace("use", "fail");')).to.be(false);
expect(detectStrictMode(';"use strict";')).to.be(false);
});
it("should not detect \"use strict\"; if it occurs in some nested function", function () {

@@ -12,0 +22,0 @@ expect(detectStrictMode('function () {"use strict";}')).to.be(false);

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc