On Feb 13, 10:10 am, Samuel Lebeau <[email protected]> wrote: > Hello, > > While fixing ticket #534 [1] _again_ (really sorry about my previous > patch), I've been wondering which convention to use when testing for > empty string. > > Original source code was showing `while (source.length > 0)` which is > really intention revealing, but while writing my patch I mecanically > wrote `if (!source) break;`, instead of `if (!source.length)` of `if > (source.length == 0)`. > I think everybody knows the empty string is a falsy value in > Javascript and the above tests are all equivalents, but what do you > guys (especially core) think about a consistent convention to use in > those cases ? > > Intention revealing versus concise code...
Besides guarding against empty strings, doesn't input need to be escaped (with `RegExp.escape`). See http://prototype.lighthouseapp.com/projects/8886/tickets/469-vertical-bar-passed-to-stringgsub-as-pattern-causes-infinite-loop -- kangax --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype: Core" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~----------~----~----~----~------~----~------~--~---
