Skip to content
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

URI malformed with dynamic route #5827

Closed
yaniv51 opened this issue May 29, 2019 · 20 comments
Closed

URI malformed with dynamic route #5827

yaniv51 opened this issue May 29, 2019 · 20 comments

Comments

@yaniv51
Copy link

yaniv51 commented May 29, 2019

Version

2.7.1

Reproduction link

https://codesandbox.io/s/examplehelloworld-quzpq

Steps to reproduce

Navigate with dynamic route to:
https://quzpq.sse.codesandbox.io/90%25

What is expected ?

Getting welcome page

What is actually happening?

Getting server error page with URI malformed error

This bug report is available on Nuxt community (#c9278)
@ghost ghost added the cmty:bug-report label May 29, 2019
@yaniv51
Copy link
Author

yaniv51 commented May 29, 2019

It is looks like it is Vue.js bug rather than Nuxt.js bug
vue-router

@pimlie
Copy link

pimlie commented Jun 5, 2019

Closing this as this is an upstream issue in vue-router, see already linked issue

Better to leave this open until the issue has been fixed in vue-router

@ThomasR
Copy link

ThomasR commented Jun 7, 2019

As far as I understand, this affects URLs containing a (properly escaped) % character (%25).

I'm experiencing a similar issue where the route on the server side always differs from the one on the client side (one is unescaped, the other one is escaped). Is that also caused by vue-router, or is this an actual Nuxt issue?

@pimlie
Copy link

pimlie commented Jun 7, 2019

@ThomasR not sure, could you show an example of what happens in your case?

@ThomasR
Copy link

ThomasR commented Jun 7, 2019

What happens is that in

asyncData({ route: { path }}) {
    consola.log('path', path);
}

I get different log outputs server-side and client-side:

Server

path /foo bar

Browser

path /foo%20bar

However, I can't reproduce this bug when creating a new Nuxt app, so it must have something to do with my application config. (Can't publish that; it's not Free Software).

I'll try and come up with a minimal example, and file a new ticket.

Edit

turns out this was a problem with my app where sometimes URLs were manually escaped before passing them to nuxt-link. Not doing so solved my issue. Sorry for the confusion

@stale
Copy link

stale bot commented Jul 2, 2019

Thanks for your contribution to Nuxt.js!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version of nuxt-edge
  2. Comment the steps to reproduce it

Issues that are labeled as pending will not be automatically marked as stale.

@stale stale bot added the stale label Jul 2, 2019
@stale stale bot closed this as completed Jul 9, 2019
@tehyo
Copy link

tehyo commented Oct 30, 2019

Still the problem with Nuxt last version, url with % produces "url malformed error"

Example url : https://zqxk0lw813.sse.codesandbox.io/?p=test%3Q
Code : https://codesandbox.io/s/github/nuxt/codesandbox-nuxt

It's a big problem because sometimes Nuxt application stops

@eddybrando
Copy link

eddybrando commented Nov 11, 2019

I still experience this problem in Nuxt v2.10.2, which uses vue-router ~3.0.7 as a dependency (in @nuxt/vue-app).

According to this issue vuejs/vue-router#2708, the vue-router double DecodeURI that was apparently causing this issue, was already fixed in vue-router v3.0.4.

Is this then an issue unique to Nuxt?

@eddybrando
Copy link

I tried to trace back the error and I believe the crash happens in nuxt.js/packages/server/src/middleware/nuxt.js:14 on await renderRoute(url, context).

The url parameter here gets decoded two lines above in const url = decodeURI(req.url), which causes the %25 to go back to %, which results in a malformed URI.

Nevertheless, removing the decodeURI results on a similar 500 error with the "URL malformed" message but just moved to another part.

Since the function renderRoute is method from a vue-renderer instance, could the problem maybe live somewhere deep in vue-renderer?

@manniL
Copy link
Member

manniL commented Nov 11, 2019

@eddybrando Yes, it could be a vue-server-render issue then I guess. Can you reproduce it with "just" the vue server renderer?

(Example reproduction of another problem: vuejs/vue#10733)

@eddybrando
Copy link

@eddybrando Yes, it could be a vue-server-render issue then I guess. Can you reproduce it with "just" the vue server renderer?

(Example reproduction of another problem: vuejs/vue#10733)

I can reproduce the error in both SSR and SPA rendering.

The SPA rendering just fails silently with a browser error log whilst the SSR returns the full error debug page.

I'm looking at the renderContext in vue-renderer to see if there is something there that could be fixed...

So far I found that renderContext.url in the renderRoute method has the decoded /path/foo/bar% version of the URL instead of the encoded one (/path/foo/bar%25), which can be found in all other URL references in said context.

But I'm still debugging...

@maunier
Copy link

maunier commented Feb 26, 2020

@eddybrando Yes, it could be a vue-server-render issue then I guess. Can you reproduce it with "just" the vue server renderer?
(Example reproduction of another problem: vuejs/vue#10733)

I can reproduce the error in both SSR and SPA rendering.

The SPA rendering just fails silently with a browser error log whilst the SSR returns the full error debug page.

I'm looking at the renderContext in vue-renderer to see if there is something there that could be fixed...

So far I found that renderContext.url in the renderRoute method has the decoded /path/foo/bar% version of the URL instead of the encoded one (/path/foo/bar%25), which can be found in all other URL references in said context.

But I'm still debugging...

I encounter this problem too. Have you got a solution?

@eddybrando
Copy link

eddybrando commented Apr 16, 2020

@eddybrando Yes, it could be a vue-server-render issue then I guess. Can you reproduce it with "just" the vue server renderer?
(Example reproduction of another problem: vuejs/vue#10733)

I can reproduce the error in both SSR and SPA rendering.
The SPA rendering just fails silently with a browser error log whilst the SSR returns the full error debug page.
I'm looking at the renderContext in vue-renderer to see if there is something there that could be fixed...
So far I found that renderContext.url in the renderRoute method has the decoded /path/foo/bar% version of the URL instead of the encoded one (/path/foo/bar%25), which can be found in all other URL references in said context.
But I'm still debugging...

I encounter this problem too. Have you got a solution?

Not really, I just avoided it by changing the way I constructed the URLs in my applications.

Do you encounter this still in the newest Nuxt version? Because I believe this is indeed a bug that should be addressed then.

If that's the case, we should probably open a new ticket and reference this there.

@maunier
Copy link

maunier commented Apr 17, 2020

i do this to solve my problem: url.replace('%', '%25%25')

@mendicm
Copy link

mendicm commented May 21, 2020

This is my current solution if you use a custom router:

In {root}/router.js:

export function createRouter(ssrContext) {
  if (ssrContext) {
    ssrContext.url = ssrContext.url.replace(/%(?![0-9A-F]{2})/g, '%25')
  }
  ...
}

@claudiolcastro
Copy link

claudiolcastro commented Jul 27, 2020

Heey, I'm using the version 2.13.3 of Nuxt.js and I'm still having this Issue. Anyone found the solution? Should this Issue be reopened? @eddybrando @maunier

I already try some aproaches by using serverMiddlware and doing some unescapes ... But I really wat to know if there is an official solution..

My url: https://localhost:3000/my-route/my-name/100%25-vote/

I'm getting the URI malformed error..

Screenshot from 2020-07-27 15-20-24

by adding this serverMiddleware on /my-route I kinda solved the issue on the serer side...

export default function (req, res, next) {
  try {
    decodeURIComponent(req.originalUrl);
    req.url = encodeURI(req.url);

    next();
  } catch (e) {
    const url = encodeURI(unescape(req.originalUrl));

    res.writeHead(302,
      { Location: url }
    );
    res.end();
  }
}

but when gets to the client side I get the URI malformed on the browser console...

thanksss!

@maunier
Copy link

maunier commented Jul 28, 2020

Heey, I'm using the version 2.13.3 of Nuxt.js and I'm still having this Issue. Anyone found the solution? Should this Issue be reopened? @eddybrando @maunier

I already try some aproaches by using serverMiddlware and doing some unescapes ... But I really wat to know if there is an official solution..

My url: https://localhost:3000/my-route/my-name/100%25-vote/

I'm getting the URI malformed error..

Screenshot from 2020-07-27 15-20-24

by adding this serverMiddleware on /my-route I kinda solved the issue on the serer side...

export default function (req, res, next) {
  try {
    decodeURIComponent(req.originalUrl);
    req.url = encodeURI(req.url);

    next();
  } catch (e) {
    const url = encodeURI(unescape(req.originalUrl));

    res.writeHead(302,
      { Location: url }
    );
    res.end();
  }
}

but when gets to the client side I get the URI malformed on the browser console...

thanksss!

Maybe you can change your route to https://localhost:3000/my-route/my-name/100%2525-vote/

@claudiolcastro
Copy link

claudiolcastro commented Jul 28, 2020

@maunier I'm trying something like that. I already saw that this is really a vue-router issue vuejs/vue-router#2725

@manniL manniL added pending and removed stale labels Jul 30, 2020
@xytaizi1230
Copy link

我遇到了相同的问题,当url中包含%时,将出现URI malformed
在.nuxt/router.js中存在decodeObj方法对字符进行解码,但是没有进行异常处理,我尝试在这段代码上增加trycatch,但是依旧回在其他地方出现此问题

@bestark
Copy link

bestark commented Dec 23, 2021

I ran into that problem today. Nuxt Version was 2.14.11. Solving the problem with updating to 2.14.12.

@danielroe danielroe added the 2.x label Jan 18, 2023
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