balderdashy / sails

Realtime MVC Framework for Node.js
https://sailsjs.com
MIT License
22.84k stars 1.95k forks source link

Sails `res.redirect` get `??` when the url param contains chinese char. #4419

Open qubaomingg opened 6 years ago

qubaomingg commented 6 years ago

Issue Describe

Hello, When I used sails res.redirect api,get some trouble.

My Code:

res.redirect('/audit?status=3000&step=/info&failreason=%E9%A9%BE%E9%BE%84%E4%B8%8D%E7%AC%A6%E5%90%88%E8%A6%81%E6%B1%82%EF%BC%88%E5%AE%9E%E9%99%85%E9%A9%BE%E9%BE%841%E5%B9%B4%E4%BB%A5%E4%B8%8A%EF%BC%89%EF%BC%9B');

But,the unexpected result in chrome:

image

the url param contains chinese word,It's ok when changed to normal character (a-Z)

My VERSION INFO

Sails version: v0.11.2 Node version: v8.9.0 NPM version: 5.6.0 Chrome version: 66.0.3359.139

Look forward to your reply,Thx!

sailsbot commented 6 years ago

Hi @freestyle21! It looks like you may have removed some required elements from the initial comment template, without which I can't verify that this post meets our contribution guidelines. To re-open this issue, please copy the template from here, paste it at the beginning of your initial comment, and follow the instructions in the text. Then post a new comment (e.g. "ok, fixed!") so that I know to go back and check.

Sorry to be a hassle, but following these instructions ensures that we can help you in the best way possible and keep the Sails project running smoothly.

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact inquiries@sailsjs.com

mikermcneil commented 6 years ago

Hey @freestyle21, thanks for posting this. Just a hunch, but is there any chance the issue is related to the /?

e.g. what if you tried wrapping that piece in encodeURIComponent()?

res.redirect(
  '/audit'+
  '?status='+encodeURIComponent(3000)+
   '&step='+encodeURIComponent('/info')+
  '&failreason='+
  '%E9%A9%BE%E9%BE%84%E4%B8%8D%E7%AC%A6%E5%90%88%E8%A6%81%E6%B1%82%EF%BC%88%E5%AE%9E%E9%99%85%E9%A9%BE%E9%BE%841%E5%B9%B4%E4%BB%A5%E4%B8%8A%EF%BC%89%EF%BC%9B'
);