From 05dce760d66ae2a7c0bb8c8868076397bdd2a970 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 10 Mar 2014 01:11:08 -0700 Subject: [PATCH] Ensure `_.truncate` doesn't truncate strings if they are equal to the given `length`. --- dist/lodash.compat.js | 2 +- dist/lodash.compat.min.js | 2 +- dist/lodash.js | 2 +- dist/lodash.min.js | 2 +- lodash.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dist/lodash.compat.js b/dist/lodash.compat.js index 3a6c75ccb..4594c6090 100644 --- a/dist/lodash.compat.js +++ b/dist/lodash.compat.js @@ -7543,7 +7543,7 @@ length = +options || 0; } string = string == null ? '' : String(string); - if (length > string.length) { + if (length >= string.length) { return string; } var end = length - omission.length; diff --git a/dist/lodash.compat.min.js b/dist/lodash.compat.min.js index eecb7d5a4..c97238e8e 100644 --- a/dist/lodash.compat.min.js +++ b/dist/lodash.compat.min.js @@ -60,7 +60,7 @@ e=typeof n;var u=typeof t;if(n===n&&(null==n||null==t||"function"!=e&&"object"!= return-1},u.mixin=xr,u.noConflict=function(){return n._=Br,this},u.noop=Cr,u.now=Fe,u.pad=function(n,t,r){n=null==n?"":Lr(n),t=+t||0;var e=n.length;return en.length)return n;var o=r-e.length;if(1>o)return e;if(r=n.slice(0,o),null==u)return r+e;if(pr(u)){if(n.slice(o).search(u)){var a,i,l=n.slice(0,o);for(u.global||(u=Tr(u.source,(D.exec(u)||"")+"g")),u.lastIndex=0;a=u.exec(l);)i=a.index; +}catch(h){throw h.source=c,h}return t?p(t):(p.source=c,p)},u.trim=Te,u.trimLeft=Le,u.trimRight=We,u.truncate=function(n,t){var r=30,e="...";if(t&&cr(t))var u="separator"in t?t.separator:u,r="length"in t?+t.length||0:r,e="omission"in t?Lr(t.omission):e;else null!=t&&(r=+t||0);if(n=null==n?"":Lr(n),r>=n.length)return n;var o=r-e.length;if(1>o)return e;if(r=n.slice(0,o),null==u)return r+e;if(pr(u)){if(n.slice(o).search(u)){var a,i,l=n.slice(0,o);for(u.global||(u=Tr(u.source,(D.exec(u)||"")+"g")),u.lastIndex=0;a=u.exec(l);)i=a.index; r=r.slice(0,null==i?o:i)}}else n.indexOf(u,o)!=o&&(u=r.lastIndexOf(u),-1n.indexOf(";")?n:n.replace(T,d))},u.uniqueId=function(n){var t=++S;return Lr(null==n?"":n)+t},u.all=Kt,u.any=nr,u.detect=Vt,u.findWhere=Vt,u.foldl=Ht,u.foldr=Jt,u.include=Ut,u.inject=Ht,xr(function(){var n={};return mt(u,function(t,r){u.prototype[r]||(n[r]=t)}),n}(),false),u.first=Nt,u.last=Wt,u.sample=function(n,t,r){return n&&typeof n.length!="number"?n=yr(n):be.unindexedChars&&hr(n)&&(n=n.split("")),null==t||r?n?n[wt(0,n.length-1)]:_:(n=Qt(n),n.length=ce(fe(0,t),n.length),n) },u.take=Nt,u.takeRight=Wt,u.takeRightWhile=Wt,u.takeWhile=Nt,u.head=Nt,mt(u,function(n,t){var r="sample"!==t;u.prototype[t]||(u.prototype[t]=function(t,e){var u=this.__chain__,a=n(this.__wrapped__,t,e);return u||null!=t&&(!e||r&&typeof t=="function")?new o(a,u):a})}),u.VERSION=E,u.prototype.chain=function(){return this.__chain__=true,this},u.prototype.toString=function(){return Lr(this.__wrapped__)},u.prototype.value=qt,u.prototype.valueOf=qt,st(["join","pop","shift"],function(n){var t=Fr[n];u.prototype[n]=function(){var n=this.__chain__,r=t.apply(this.__wrapped__,arguments); return n?new o(r,n):r}}),st(["push","reverse","sort","unshift"],function(n){var t=Fr[n];u.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),st(["concat","splice"],function(n){var t=Fr[n];u.prototype[n]=function(){return new o(t.apply(this.__wrapped__,arguments),this.__chain__)}}),be.spliceObjects||st(["pop","shift","splice"],function(n){var t=Fr[n],r="splice"==n;u.prototype[n]=function(){var n=this.__chain__,e=this.__wrapped__,u=t.apply(e,arguments);return 0===e.length&&delete e[0],n||r?new o(u,n):u diff --git a/dist/lodash.js b/dist/lodash.js index 9a14e1802..a727a6e70 100644 --- a/dist/lodash.js +++ b/dist/lodash.js @@ -7316,7 +7316,7 @@ length = +options || 0; } string = string == null ? '' : String(string); - if (length > string.length) { + if (length >= string.length) { return string; } var end = length - omission.length; diff --git a/dist/lodash.min.js b/dist/lodash.min.js index 237b5c6c3..768a8f157 100644 --- a/dist/lodash.min.js +++ b/dist/lodash.min.js @@ -56,7 +56,7 @@ return u},u.toArray=function(n){return n&&typeof n.length=="number"?Wt(n):hr(n)} var e=n.length;return en.length)return n;var o=r-e.length;if(1>o)return e;if(r=n.slice(0,o),null==u)return r+e;if(lr(u)){if(n.slice(o).search(u)){var i,a,f=n.slice(0,o);for(u.global||(u=Er(u.source,(L.exec(u)||"")+"g")),u.lastIndex=0;i=u.exec(f);)a=i.index; +}catch(h){throw h.source=c,h}return t?s(t):(s.source=c,s)},u.trim=Ae,u.trimLeft=Ie,u.trimRight=Ee,u.truncate=function(n,t){var r=30,e="...";if(t&&ar(t))var u="separator"in t?t.separator:u,r="length"in t?+t.length||0:r,e="omission"in t?Rr(t.omission):e;else null!=t&&(r=+t||0);if(n=null==n?"":Rr(n),r>=n.length)return n;var o=r-e.length;if(1>o)return e;if(r=n.slice(0,o),null==u)return r+e;if(lr(u)){if(n.slice(o).search(u)){var i,a,f=n.slice(0,o);for(u.global||(u=Er(u.source,(L.exec(u)||"")+"g")),u.lastIndex=0;i=u.exec(f);)a=i.index; r=r.slice(0,null==a?o:a)}}else n.indexOf(u,o)!=o&&(u=r.lastIndexOf(u),-1n.indexOf(";")?n:n.replace(S,m))},u.uniqueId=function(n){var t=++I;return Rr(null==n?"":n)+t},u.all=qt,u.any=Ht,u.detect=Pt,u.findWhere=Pt,u.foldl=Yt,u.foldr=Zt,u.include=Bt,u.inject=Yt,br(function(){var n={};return gt(u,function(t,r){u.prototype[r]||(n[r]=t)}),n}(),false),u.first=Et,u.last=St,u.sample=function(n,t,r){return n&&typeof n.length!="number"&&(n=hr(n)),null==t||r?n?n[dt(0,n.length-1)]:b:(n=Gt(n),n.length=ue(ee(0,t),n.length),n) },u.take=Et,u.takeRight=St,u.takeRightWhile=St,u.takeWhile=Et,u.head=Et,gt(u,function(n,t){var r="sample"!==t;u.prototype[t]||(u.prototype[t]=function(t,e){var u=this.__chain__,i=n(this.__wrapped__,t,e);return u||null!=t&&(!e||r&&typeof t=="function")?new o(i,u):i})}),u.VERSION=O,u.prototype.chain=function(){return this.__chain__=true,this},u.prototype.toString=function(){return Rr(this.__wrapped__)},u.prototype.value=zt,u.prototype.valueOf=zt,ft(["join","pop","shift"],function(n){var t=Sr[n];u.prototype[n]=function(){var n=this.__chain__,r=t.apply(this.__wrapped__,arguments); return n?new o(r,n):r}}),ft(["push","reverse","sort","unshift"],function(n){var t=Sr[n];u.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),ft(["concat","splice"],function(n){var t=Sr[n];u.prototype[n]=function(){return new o(t.apply(this.__wrapped__,arguments),this.__chain__)}}),u}var b,_=1,w=2,x=4,k=8,j=16,C=32,O="2.4.1",A="__lodash@"+O+"__",I=0,E=/\b__p\+='';/g,R=/\b(__p\+=)''\+/g,N=/(__e\(.*?\)|\b__t\))\+'';/g,S=/&(?:amp|lt|gt|quot|#39);/g,T=/[&<>"']/g,W=/<%-([\s\S]+?)%>/g,F=/<%([\s\S]+?)%>/g,$=/<%=([\s\S]+?)%>/g,D=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,L=/\w*$/,z=/^\s*function[ \n\r\t]+\w/,B=/^0[xX]/,q=/[\xC0-\xFF]/g,U=/($^)/,P=/[.*+?^${}()|[\]\\]/g,K=/\bthis\b/,M=/['\n\r\t\u2028\u2029\\]/g,V=/[a-zA-Z0-9][a-z0-9]*/g,X=" \t\x0B\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000",Y="Array Boolean Date Function Math Number Object RegExp Set String _ clearTimeout document isFinite isNaN parseInt setTimeout TypeError window WinRTError".split(" "),Z="[object Arguments]",G="[object Array]",H="[object Boolean]",J="[object Date]",Q="[object Function]",nt="[object Number]",tt="[object Object]",rt="[object RegExp]",et="[object String]",ut={}; diff --git a/lodash.js b/lodash.js index d2a2b9481..5b1cacf55 100644 --- a/lodash.js +++ b/lodash.js @@ -7562,7 +7562,7 @@ length = +options || 0; } string = string == null ? '' : String(string); - if (length > string.length) { + if (length >= string.length) { return string; } var end = length - omission.length;