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.

URL incorrectly adds trailing slash

See original GitHub issue

🐛 Bug Report

URL polyfill in React Native 0.59 is broken because it’s not compliant to WHATWG URL Standard. And it’s broken even for the simplest use cases.

To Reproduce

const url = new URL('https://facebook.github.io/react-native/img/header_logo.png');
console.log(url);

Expected Behavior

https://facebook.github.io/react-native/img/header_logo.png

Actual Behavior

https://facebook.github.io/react-native/img/header_logo.png/

Note the trailing slash causes the URL points to a 404 page.

Environment

  React Native Environment Info:
    System:
      OS: macOS 10.14.4
      CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
      Memory: 823.64 MB / 16.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 10.15.0
      Yarn: 1.15.2
      npm: 6.5.0
      Watchman: 4.9.0
    SDKs:
      iOS SDK:
        Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
      Android SDK:
        API Levels: 28
        Build Tools: 28.0.3
        System Images: android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom
    IDEs:
      Android Studio: 3.3 AI-182.5107.16.33.5314842
      Xcode: 10.2/10E125 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.8.3 => 16.8.3 
      react-native: 0.59.4 => 0.59.4 

Possible Cause

https://github.com/facebook/react-native/blob/65033d7078654bae2a87e4791dbb725110ae6bad/Libraries/Blob/URL.js#L146-L149

This code was introduced in https://github.com/facebook/react-native/pull/22901 .

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
charpenicommented, Nov 25, 2019
1reaction
redreceiptcommented, Oct 28, 2019

I’ll second this issue, having to add a goofy workaround

    const url = new URL(baseURL);
    // NOTE: RN adds a trailing slash
    // https://github.com/facebook/react-native/issues/24428
    url._url = url.toString().endsWith('/')
      ? url.toString().slice(0, -1)
      : url.toString();
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix internal redirects from trailing slash mismatch?
This issue means that the one URL on your site is redirected to another internal URL. The presence/absence of a trailing slash is...
Read more >
sometimes incorrectly appends slash on URLs (when both ...
Chrome add a slash at the end of the URL, resulting on a wrong parameter: ... the fact that the route may have...
Read more >
Trailing Slashes and SEO - Best Practice Guide
Historically, a trailing slash marked a directory and a URL without a trailing slash at the end used to mean that the URL...
Read more >
When should I use a trailing slash in my URL?
No trailing slash is helpful for working with relative sub-paths AND also trailing slash is improper when the url denotes a resource. So...
Read more >
What Is a Trailing Slash in URL & How Does It Affect SEO?
Every SEO specialist needs to deal with duplicate content on a regular basis. Sometimes, it turns out that inappropriate use of the ...
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