git-static icon indicating copy to clipboard operation
git-static copied to clipboard

ignore url query strings in file path

Open alancmclean opened this issue 11 years ago • 4 comments

URL Query strings are included in the file path causing "file not found" errors. This should workaround that. Nothing fancy, just a split on the first ? encountered in the file path.

alancmclean avatar Jan 19 '15 21:01 alancmclean

Better would be something like this:

function defaultFile(url) {
  var i = url.indexOf("/", 1) + 1,
      j = url.indexOf("?", i + 1);
  return decodeURIComponent(url.substring(i, j < 0 ? url.length : j));
}

But of course this is still a pretty poor URL parser, but it’s probably okay for something intended to be overridden.

Best would to add some tests. ;)

mbostock avatar Jan 20 '15 16:01 mbostock

Yep, this is a lot nicer. Will update. Introducing tests seems like a separate PR maybe? Got a preference for testing?

alancmclean avatar Jan 21 '15 06:01 alancmclean

That was more a note to myself re. tests. But I’d probably use vows (which is a little long in the tooth but I haven’t bothered to learn a replacement yet) as seen in the smash repo.

mbostock avatar Jan 21 '15 17:01 mbostock

Updated with your feedback verbatim.

alancmclean avatar Jan 26 '15 20:01 alancmclean