Code review comment for lp:~bcsaller/juju-gui/namespace-routing

Revision history for this message
Benjamin Saller (bcsaller) wrote :

Thanks, I've included the minors, I didn't change to the regex because
of the escaping. If someone else needs this sort of method I'd be happy
to improve those for reuse but we made it pretty far w/o.

https://codereview.appspot.com/7327045/diff/16001/app/assets/javascripts/routing.js
File app/assets/javascripts/routing.js (right):

https://codereview.appspot.com/7327045/diff/16001/app/assets/javascripts/routing.js#newcode5
app/assets/javascripts/routing.js:5: function _trim(s, char, leading,
trailing) {
On 2013/02/18 20:00:06, benji wrote:
> On 2013/02/18 17:12:47, jeff.pihach wrote:
> > This feels like a generic utility method which could be split out
into a
> > separate utility method module

> +1 I'm surprised trimming strings isn't already available in JS or
YUI.

> > and hung off Y.Lang so that it's available application wide.

> -1 to injecting ourselves into a third-party library

> > As a generic utility method it would probably be best solved using a
regex. Ln
> > 5-18 could be replaced with:
> >
> > ** WARNING - incoming untested code **
> >
> > Y.Lang.trimString = function(str, start, end) {
> >
> > var trimRegex = new RegExp("^[" + start + "]+|[" + end +
"]+$","g");
> > return str.replace(trimRegex, "");
> >
> > }

> Building regexes programmatically requires escaping the inputs.

> For example, what if I want to trim any leading "bar" off a string and
I pass in
> "bar" as the start parameter and "rabid" as the str. Instead of
getting "rabid"
> back (because the prefix wasn't there to get removed) I instead get
back "id"
> because my start string was interpreted as a set of characters not a
literal
> string.

Done.

https://codereview.appspot.com/7327045/diff/16001/app/assets/javascripts/routing.js#newcode96
app/assets/javascripts/routing.js:96: console.log('URL has more than one
refernce to same namespace');
On 2013/02/18 17:12:47, jeff.pihach wrote:
> s/refernce/reference :-) also see above comment about Y.log()

Done.

https://codereview.appspot.com/7327045/diff/16001/app/assets/javascripts/routing.js#newcode113
app/assets/javascripts/routing.js:113: var u = '/';
On 2013/02/18 17:12:47, jeff.pihach wrote:
> u is url? Please don't manually minify - use meaningful variable names
</pet
> peeve> :-)

Done.

https://codereview.appspot.com/7327045/

« Back to merge proposal