8000 fetch() with URL object errors: "url.match is not a function" · Issue #25538 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

fetch() with URL object errors: "url.match is not a function" #25538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hlb-schmidt opened this issue Dec 18, 2017 · 4 comments
Closed

fetch() with URL object errors: "url.match is not a function" #25538

hlb-schmidt opened this issue Dec 18, 2017 · 4 comments

Comments

@hlb-schmidt
Copy link
Q A
Bug report? yes
Feature request? no
BC Break report? dunno
RFC? dunno
Symfony version 3.3.10

to reproduce, open a page that has the symfony profiler, and then in browser devtools javascript console run following:

  • fetch("https://symfony.com") works as intended, we get a CORS error.

  • fetch(new URL("https://symfony.com")) also gets the CORS error, but also a fatal error url.match is not a function that points to a oneliner added by symfony.

i guess its the symfony profiler assuming the url in fetch is a string...

@hlb-schmidt
Copy link
Author

for a quick fix i added locally:

if (url instanceof URL) {
	url = url.href;
}

before https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig#L244

i guess for a real fix we want to use paramType...

@hlb-schmidt
Copy link
Author

i guess this could be a proper fix

diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig b/src/Symfony/Bundle/WebP
rofilerBundle/Resources/views/Profiler/base_js.html.twig
index e83e95a..7f0a4f0 100644
--- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig
+++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig
@@ -250,6 +250,8 @@
                             mode: arguments[0].mode,
                             redirect: arguments[0].redirect
                         };
+                    } else if (paramType === '[object URL]') {
+                        url = url.href
                     }
                     if (!url.match(new RegExp({{ excluded_ajax_paths|json_encode|raw }}))) {
                         var method = 'GET';

ps. i know nothing about symfony internals!

@hlb-schmidt
Copy link
Author

or, to follow the if before:

url = arguments[0].href

@ro0NL
Copy link
Contributor
ro0NL commented Dec 19, 2017

Status: reviewed

fabpot added a commit that referenced this issue Dec 20, 2017
This PR was merged into the 3.3 branch.

Discussion
----------

[WebProfilerBundle] Let fetch() cast URL to string

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #25538
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!--highly recommended for new features-->

Taken from the fetch polyfill at https://github.com/github/fetch/blob/master/fetch.js#L325

Commits
-------

1a75e85 [WebProfilerBundle] Let fetch() cast URL to string
@fabpot fabpot closed this as completed Dec 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
0