From 9aa56630ab32c926113ba6f7b3a4fec810bc012a Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 20 Jan 2016 23:13:18 -0600 Subject: [PATCH] Ensure `_.noConflict` only restores `_` if `lodash` is the current `_` value. --- lodash.js | 4 +++- test/test.js | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lodash.js b/lodash.js index 14bced112..f511c67d6 100644 --- a/lodash.js +++ b/lodash.js @@ -13230,7 +13230,9 @@ * var lodash = _.noConflict(); */ function noConflict() { - root._ = oldDash; + if (root._ === this) { + root._ = oldDash; + } return this; } diff --git a/test/test.js b/test/test.js index d1eaaa37a..ff1f771f8 100644 --- a/test/test.js +++ b/test/test.js @@ -14297,6 +14297,20 @@ } }); + QUnit.test('should restore `_` only if `lodash` is the current `_` value', function(assert) { + assert.expect(2); + + if (!isModularize) { + var object = root._ = {}; + assert.strictEqual(_.noConflict(), oldDash); + assert.strictEqual(root._, object); + root._ = oldDash; + } + else { + skipTest(assert, 2); + } + }); + QUnit.test('should work with a `root` of `this`', function(assert) { assert.expect(2);