From d9c95e77307d9abef213340e4f75bd75c4d92fe3 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 12 Feb 2013 00:23:57 -0800 Subject: [PATCH] Escape `}` in regexes used in lodash.js. [closes #179] Former-commit-id: 7b4687f3967079e19025fccc3f54b7fc5fcc4ff9 --- build.js | 6 +++--- dist/lodash.compat.js | 6 +++--- dist/lodash.compat.min.js | 2 +- dist/lodash.js | 4 ++-- dist/lodash.min.js | 2 +- dist/lodash.underscore.js | 4 ++-- doc/README.md | 2 +- lodash.js | 6 +++--- test/test-build.js | 2 +- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/build.js b/build.js index 0c8ff1603..0d61124d7 100755 --- a/build.js +++ b/build.js @@ -581,7 +581,7 @@ ' lodash template=... File path pattern used to match template files to precompile', ' (e.g. `lodash template=./*.jst`)', ' lodash settings=... Template settings used when precompiling templates', - ' (e.g. `lodash settings="{interpolate:/\\{\\{([\\s\\S]+?)\\}\\}/g}"`)', + ' (e.g. `lodash settings="{interpolate:/{{([\\s\\S]+?)}}/g}"`)', ' lodash moduleId=... The AMD module ID of Lo-Dash, which defaults to “lodash”, used by precompiled templates', '', ' All arguments, except `legacy` with `csp`, `mobile`, `modern`, or `underscore`, may be combined.', @@ -2237,7 +2237,7 @@ .replace(/'(?:\\n|\s)+'/g, "''") .replace(/__p *\+= *' *';/g, '') .replace(/(__p *\+= *)' *' *\+/g, '$1') - .replace(/({) *;|; *(\})/g, '$1$2') + .replace(/({) *;|; *(})/g, '$1$2') .replace(/\(\(__t *= *\( *([^)]+) *\)\) *== *null *\? *'' *: *__t\)/g, '($1)'); // remove the with-statement @@ -2245,7 +2245,7 @@ // minor cleanup snippet = snippet - .replace(/obj *\|\| *\(obj *= *\{}\);/, '') + .replace(/obj *\|\| *\(obj *= *{}\);/, '') .replace(/var __p = '';\s*__p \+=/, 'var __p ='); // remove comments, including sourceURLs diff --git a/dist/lodash.compat.js b/dist/lodash.compat.js index 954f452e4..951467e70 100644 --- a/dist/lodash.compat.js +++ b/dist/lodash.compat.js @@ -56,7 +56,7 @@ * Used to match ES6 template delimiters * http://people.mozilla.org/~jorendorff/es6-draft.html#sec-7.8.6 */ - var reEsTemplate = /\$\{((?:(?=\\?)\\?[\s\S])*?)}/g; + var reEsTemplate = /\$\{((?:(?=\\?)\\?[\s\S])*?)\}/g; /** Used to match "interpolate" template delimiters */ var reInterpolate = /<%=([\s\S]+?)%>/g; @@ -153,7 +153,7 @@ var hasObjectSpliceBug = (hasObjectSpliceBug = { '0': 1, 'length': 1 }, arrayRef.splice.call(hasObjectSpliceBug, 0, 1), hasObjectSpliceBug[0]); - /** Detect if `arguments` object indexes are non-enumerable (Firefox < 4, IE < 9, Safari < 5.1) */ + /** Detect if `arguments` object indexes are non-enumerable (Firefox < 4, IE < 9, PhantomJS, Safari < 5.1) */ var nonEnumArgs = true; (function() { @@ -4557,7 +4557,7 @@ * http://lodash.com/#custom-builds * * For more information on Chrome extension sandboxes see: - * http://developer.chrome.com/trunk/extensions/sandboxingEval.html + * http://developer.chrome.com/stable/extensions/sandboxingEval.html * * @static * @memberOf _ diff --git a/dist/lodash.compat.min.js b/dist/lodash.compat.min.js index 5cab19ccd..f5432a39c 100644 --- a/dist/lodash.compat.min.js +++ b/dist/lodash.compat.min.js @@ -19,7 +19,7 @@ return n}function F(n,t,r){var e=-1,u=n?n.length:0,o=Array(typeof u=="number"?u: });return r}function T(n,t,r,e){var u=n,o=n?n.length:0,i=3>arguments.length;if(typeof o!="number")var a=pr(n),o=a.length;else Xt&&A(n)&&(u=n.split(""));return t=f(t,e,4),$(n,function(n,e,f){e=a?a[--o]:--o,r=i?(i=W,u[e]):t(r,u[e],e,f)}),r}function B(n,t,r){var e;if(t=f(t,r),lr(n)){r=-1;for(var u=n.length;++rr?$t(0,u+r):r||0)-1;else if(r)return e=K(n,t),n[e]===t?e:-1;for(;++e>>1,r(n[e])z(a,p))&&((r||c)&&a.push(p),i.push(e))}return i}function U(n,t){return Vt||Et&&2/g,yt=/($^)/,mt=/[&<>"']/g,_t=/['\n\r\t\u2028\u2029\\]/g,dt="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),bt=Math.ceil,wt=rt.concat,jt=Math.floor,xt=vt.test(xt=Object.getPrototypeOf)&&xt,Ot=et.hasOwnProperty,At=rt.push,St=et.toString,Et=vt.test(Et=v.bind)&&Et,kt=vt.test(kt=Array.isArray)&&kt,qt=n.isFinite,Nt=n.isNaN,Rt=vt.test(Rt=Object.keys)&&Rt,$t=Math.max,Ft=Math.min,Dt=Math.random,It="[object Arguments]",Tt="[object Array]",Bt="[object Boolean]",Mt="[object Date]",Pt="[object Number]",zt="[object Object]",Ct="[object RegExp]",Kt="[object String]",Lt=!!n.attachEvent,Ut=Et&&!/\n|true/.test(Et+Lt),Vt=Et&&!Ut,Gt=Rt&&(Lt||Ut),Ht=(Ht={0:1,length:1},rt.splice.call(Ht,0,1),Ht[0]),Jt=J; +r.prototype[t]=function(){var n=[this.__wrapped__];return At.apply(n,arguments),new r(e.apply(r,n))}})}function H(){return this.__wrapped__}var J=!0,Q=null,W=!1,X=typeof exports=="object"&&exports,Y=typeof global=="object"&&global;Y.global===Y&&(n=Y);var Z,nt,tt,rt=[],et={},ut=0,ot=et,it=30,ft=n._,at=/&(?:amp|lt|gt|quot|#39);/g,ct=/\b__p\+='';/g,lt=/\b(__p\+=)''\+/g,pt=/(__e\(.*?\)|\b__t\))\+'';/g,st=/\w*$/,vt=RegExp("^"+(et.valueOf+"").replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),gt=/\$\{((?:(?=\\?)\\?[\s\S])*?)\}/g,ht=/<%=([\s\S]+?)%>/g,yt=/($^)/,mt=/[&<>"']/g,_t=/['\n\r\t\u2028\u2029\\]/g,dt="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),bt=Math.ceil,wt=rt.concat,jt=Math.floor,xt=vt.test(xt=Object.getPrototypeOf)&&xt,Ot=et.hasOwnProperty,At=rt.push,St=et.toString,Et=vt.test(Et=v.bind)&&Et,kt=vt.test(kt=Array.isArray)&&kt,qt=n.isFinite,Nt=n.isNaN,Rt=vt.test(Rt=Object.keys)&&Rt,$t=Math.max,Ft=Math.min,Dt=Math.random,It="[object Arguments]",Tt="[object Array]",Bt="[object Boolean]",Mt="[object Date]",Pt="[object Number]",zt="[object Object]",Ct="[object RegExp]",Kt="[object String]",Lt=!!n.attachEvent,Ut=Et&&!/\n|true/.test(Et+Lt),Vt=Et&&!Ut,Gt=Rt&&(Lt||Ut),Ht=(Ht={0:1,length:1},rt.splice.call(Ht,0,1),Ht[0]),Jt=J; (function(){function n(){this.x=1}var t=[];n.prototype={valueOf:1,y:1};for(var r in new n)t.push(r);for(r in arguments)Jt=!r;Z=!/valueOf/.test(t),nt=n.propertyIsEnumerable("prototype"),tt="x"!=t[0]})(1);var Qt=arguments.constructor==Object,Wt=!h(arguments),Xt="xx"!="x"[0]+Object("x")[0];try{var Yt=St.call(document)==zt&&!({toString:0}+"")}catch(Zt){}var nr={"[object Function]":W};nr[It]=nr[Tt]=nr[Bt]=nr[Mt]=nr[Pt]=nr[zt]=nr[Ct]=nr[Kt]=J;var tr={};tr[Tt]=Array,tr[Bt]=Boolean,tr[Mt]=Date,tr[zt]=Object,tr[Pt]=Number,tr[Ct]=RegExp,tr[Kt]=String; var rr={"boolean":W,"function":J,object:J,number:W,string:W,undefined:W},er={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};r.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:ht,variable:"",imports:{_:r}};var ur={a:"p,v,g",l:"var a=0,b=typeof g=='number'?2:arguments.length;while(++a":">",'"':""","'":"'"},vr=b(sr),gr=a(ur),hr=a(ur,{h:"if(t[i]==null)"+ur.h});j(/x/)&&(j=function(n){return n instanceof Function||"[object Function]"==St.call(n)});var yr=xt?function(n){if(!n||typeof n!="object")return W; diff --git a/dist/lodash.js b/dist/lodash.js index 3cff39380..9cb742f0e 100644 --- a/dist/lodash.js +++ b/dist/lodash.js @@ -56,7 +56,7 @@ * Used to match ES6 template delimiters * http://people.mozilla.org/~jorendorff/es6-draft.html#sec-7.8.6 */ - var reEsTemplate = /\$\{((?:(?=\\?)\\?[\s\S])*?)}/g; + var reEsTemplate = /\$\{((?:(?=\\?)\\?[\s\S])*?)\}/g; /** Used to match "interpolate" template delimiters */ var reInterpolate = /<%=([\s\S]+?)%>/g; @@ -4407,7 +4407,7 @@ * http://lodash.com/#custom-builds * * For more information on Chrome extension sandboxes see: - * http://developer.chrome.com/trunk/extensions/sandboxingEval.html + * http://developer.chrome.com/stable/extensions/sandboxingEval.html * * @static * @memberOf _ diff --git a/dist/lodash.min.js b/dist/lodash.min.js index bf768f941..7cdd94c93 100644 --- a/dist/lodash.min.js +++ b/dist/lodash.min.js @@ -18,7 +18,7 @@ return n}function R(n,t,r){var e=-1,u=n?n.length:0,o=Array(typeof u=="number"?u: });return r}function D(n,t,r,e){var u=n?n.length:0,o=3>arguments.length;if(typeof u!="number")var i=Qt(n),u=i.length;return t=f(t,e,4),N(n,function(e,f,a){f=i?i[--u]:--u,r=o?(o=!1,n[f]):t(r,n[f],f,a)}),r}function T(n,t,r){var e;if(t=f(t,r),Lt(n)){r=-1;for(var u=n.length;++rr?xt(0,u+r):r||0)-1;else if(r)return e=P(n,t),n[e]===t?e:-1;for(;++e>>1,r(n[e])M(a,p))&&((r||c)&&a.push(p),i.push(e))}return i}function K(n,t){return Bt||_t&&2/g,at=/($^)/,ct=/[&<>"']/g,lt=/['\n\r\t\u2028\u2029\\]/g,pt=Math.ceil,st=L.concat,vt=Math.floor,gt=ot.test(gt=Object.getPrototypeOf)&>,ht=Q.hasOwnProperty,yt=L.push,mt=Q.toString,_t=ot.test(_t=s.bind)&&_t,dt=ot.test(dt=Array.isArray)&&dt,bt=n.isFinite,wt=n.isNaN,jt=ot.test(jt=Object.keys)&&jt,xt=Math.max,At=Math.min,Ot=Math.random,Et="[object Arguments]",St="[object Array]",qt="[object Boolean]",kt="[object Date]",Nt="[object Number]",Rt="[object Object]",$t="[object RegExp]",Ft="[object String]",Dt=!!n.attachEvent,Tt=_t&&!/\n|true/.test(_t+Dt),Bt=_t&&!Tt,It=jt&&(Dt||Tt),Mt={"[object Function]":!1}; +r.prototype[t]=function(){var n=[this.__wrapped__];return yt.apply(n,arguments),new r(e.apply(r,n))}})}function G(){return this.__wrapped__}var H=typeof exports=="object"&&exports,J=typeof global=="object"&&global;J.global===J&&(n=J);var L=[],Q={},W=0,X=Q,Y=30,Z=n._,nt=/&(?:amp|lt|gt|quot|#39);/g,tt=/\b__p\+='';/g,rt=/\b(__p\+=)''\+/g,et=/(__e\(.*?\)|\b__t\))\+'';/g,ut=/\w*$/,ot=RegExp("^"+(Q.valueOf+"").replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),it=/\$\{((?:(?=\\?)\\?[\s\S])*?)\}/g,ft=/<%=([\s\S]+?)%>/g,at=/($^)/,ct=/[&<>"']/g,lt=/['\n\r\t\u2028\u2029\\]/g,pt=Math.ceil,st=L.concat,vt=Math.floor,gt=ot.test(gt=Object.getPrototypeOf)&>,ht=Q.hasOwnProperty,yt=L.push,mt=Q.toString,_t=ot.test(_t=s.bind)&&_t,dt=ot.test(dt=Array.isArray)&&dt,bt=n.isFinite,wt=n.isNaN,jt=ot.test(jt=Object.keys)&&jt,xt=Math.max,At=Math.min,Ot=Math.random,Et="[object Arguments]",St="[object Array]",qt="[object Boolean]",kt="[object Date]",Nt="[object Number]",Rt="[object Object]",$t="[object RegExp]",Ft="[object String]",Dt=!!n.attachEvent,Tt=_t&&!/\n|true/.test(_t+Dt),Bt=_t&&!Tt,It=jt&&(Dt||Tt),Mt={"[object Function]":!1}; Mt[Et]=Mt[St]=Mt[qt]=Mt[kt]=Mt[Nt]=Mt[Rt]=Mt[$t]=Mt[Ft]=!0;var zt={};zt[St]=Array,zt[qt]=Boolean,zt[kt]=Date,zt[Rt]=Object,zt[Nt]=Number,zt[$t]=RegExp,zt[Ft]=String;var Pt={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},Ct={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};r.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:ft,variable:"",imports:{_:r}};var Kt={a:"p,v,g",l:"var a=0,b=typeof g=='number'?2:arguments.length;while(++a":">",'"':""","'":"'"},Xt=_(Wt),Yt=a(Kt),Zt=a(Kt,{h:"if(t[i]==null)"+Kt.h});b(/x/)&&(b=function(n){return n instanceof Function||"[object Function]"==mt.call(n)});var nr=function(n){if(!n||typeof n!="object")return!1;var t=n.valueOf,r=typeof t=="function"&&(r=gt(t))&>(r);if(r)n=n==r||gt(n)==r&&!g(n);else{var e=!1;!n||typeof n!="object"||g(n)?n=e:(t=n.constructor,!b(t)||t instanceof t?(Ht(n,function(n,t){e=t}),n=!1===e||ht.call(n,e)):n=e) }return n};r.after=function(n,t){return 1>n?t():function(){return 1>--n?t.apply(this,arguments):void 0}},r.assign=Yt,r.at=function(n){for(var t=-1,r=st.apply(L,s(arguments,1)),e=r.length,u=Array(e);++t/g; @@ -3818,7 +3818,7 @@ * http://lodash.com/#custom-builds * * For more information on Chrome extension sandboxes see: - * http://developer.chrome.com/trunk/extensions/sandboxingEval.html + * http://developer.chrome.com/stable/extensions/sandboxingEval.html * * @static * @memberOf _ diff --git a/doc/README.md b/doc/README.md index f4d547d5d..2e8c47a73 100644 --- a/doc/README.md +++ b/doc/README.md @@ -3311,7 +3311,7 @@ For more information on precompiling templates see:
http://lodash.com/#custom-builds For more information on Chrome extension sandboxes see:
-http://developer.chrome.com/trunk/extensions/sandboxingEval.html +http://developer.chrome.com/stable/extensions/sandboxingEval.html #### Arguments 1. `text` *(String)*: The template text. diff --git a/lodash.js b/lodash.js index c1d527f52..5b3d6585c 100644 --- a/lodash.js +++ b/lodash.js @@ -55,7 +55,7 @@ * Used to match ES6 template delimiters * http://people.mozilla.org/~jorendorff/es6-draft.html#sec-7.8.6 */ - var reEsTemplate = /\$\{((?:(?=\\?)\\?[\s\S])*?)}/g; + var reEsTemplate = /\$\{((?:(?=\\?)\\?[\s\S])*?)\}/g; /** Used to match "interpolate" template delimiters */ var reInterpolate = /<%=([\s\S]+?)%>/g; @@ -152,7 +152,7 @@ var hasObjectSpliceBug = (hasObjectSpliceBug = { '0': 1, 'length': 1 }, arrayRef.splice.call(hasObjectSpliceBug, 0, 1), hasObjectSpliceBug[0]); - /** Detect if `arguments` object indexes are non-enumerable (Firefox < 4, IE < 9, Safari < 5.1) */ + /** Detect if `arguments` object indexes are non-enumerable (Firefox < 4, IE < 9, PhantomJS, Safari < 5.1) */ var nonEnumArgs = true; (function() { @@ -4564,7 +4564,7 @@ * http://lodash.com/#custom-builds * * For more information on Chrome extension sandboxes see: - * http://developer.chrome.com/trunk/extensions/sandboxingEval.html + * http://developer.chrome.com/stable/extensions/sandboxingEval.html * * @static * @memberOf _ diff --git a/test/test-build.js b/test/test-build.js index 24caba685..f46746912 100644 --- a/test/test-build.js +++ b/test/test-build.js @@ -561,7 +561,7 @@ asyncTest('`lodash settings=...`' + (command ? ' ' + command : ''), function() { var start = _.after(2, _.once(QUnit.start)); - build(['-s', 'template=' + templatePath + '/*.tpl', 'settings={interpolate:/\\{\\{([\\s\\S]+?)\\}\\}/}'].concat(command || []), function(data) { + build(['-s', 'template=' + templatePath + '/*.tpl', 'settings={interpolate:/{{([\\s\\S]+?)}}/}'].concat(command || []), function(data) { var moduleId, basename = path.basename(data.outputPath, '.js'), context = createContext();