question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[minor] Bug in ObjectLoader's URL regex

See original GitHub issue

The regex in question:

/^(\/\/)|([a-z]+:(\/\/)?)/i

The second part of the branch should also have a ^.


How about this instead?

/^(\/|[a-z][a-z0-9\+\.\-]*:)/i

Reasoning:

  • The ^ needs to be outside of the group with |, so that it applies to both. Currently, it matches “a/x?y:z”, which is a relative path.
  • A single slash begins a relative URL to an absolute path, so only check for one slash. Currently, “/a?b=c” can turn into “http://example.com/texture/path//a?b=c”.
  • The URI scheme (the part before the :) is as specified on Wikipedia.
    • The backslashes in the character class aren’t strictly necessary.
  • The check for “maybe two slashes” in the second branch is redundant. (Optional tails don’t affect regex tests.)
  • Removed redundant parentheses.

The scheme part of the regex could be [a-z]+ for the sake of performance. Most schemes of interest only use letters. However, the cost of the regex test will probably be much smaller than the cost of loading the image itself.

The single-leading-slash case might need to be handled separately. Maybe an absolute path should resolve to “http://example.com/a?b=c” instead of “http://example.com/texture/path//a?b=c”. That’s something that needs to be decided and documented.

Also, “https:/a?b=c” is supposedly valid as an absolute path relative to the current host over a different protocol. It’s unlikely that anyone will use that, though, and both Chrome and Firefox resolve that path to “https://a?b=c”.


Alternatively, the regex can be replaced by a path-resolving utility function. If we don’t want a library, we should find a well-tested snippet somewhere.

Since Not Invented Here is more fun, I found a few ways of implementing it. Here’s one using the URL constructor (which might require the above shim):

path = new URL(image.url, scope.texturePath).href;

I think scope.texturePath must be an absolute URL (not path) here.


It’s, uh, just a minor bug.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Mugen87commented, Jan 25, 2020

Closing. Let’s only change the regex in ObjectLoader if other users reports issues in that regard. AFAIK, this was not the case since 2016.

0reactions
mrdoobcommented, Oct 28, 2016

https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest says that responseType = 'json' is not supported on Internet Explorer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug in Java regex implementation? - Stack Overflow
I've verified this unexpected behavior exists in Java version 1.7.0_11 on Ubuntu linux and also Java version 1.6.0_37 on OSX 10.8.2. I reported ......
Read more >
153442 – Replacement for CookieAction/NodeAction
We've been talking about a ContextAwareAction-based replacement for CookieAction/NodeAction for about five years now. So, here is one.
Read more >
jvm running Eclipse Mars.2 crashes after upgrade to patch 92
Type: Bug; Component: hotspot; Sub-Component: compiler; Affected Version: 8u92 ... instanceKlass org/eclipse/jface/text/link/LinkedModeManager instanceKlass ...
Read more >
Demystifying regular expression bugs - Chris Brown
We conduct an empirical study of 356 regex-related bugs from merged pull requests in Apache, Mozilla, Facebook, and Google GitHub reposi- tories. We...
Read more >
gerrit - Git at Google
These updates will be included in the next minor release. ... This means old stable branches - should only receive bug-fixes that are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found