Query string parsing is truncated by an apostrophe in Node.js

I am creating a server in Node.js that receives data from Javascript on a website. Data is sent using the jQuery getJSON method, for example:

$.getJSON(
    url,
    {
        id: track.id,
        artist: track.artist,
        title: track.title,
        album: track.album,
        filename: track.filename,
        user: track.user,
        userId: track.userId,
        room: track.room,
        timestamp: track.timestamp
    }
);

Then I try to get the data using the url Node module as follows:

var urlObj = url.parse(request.url, true);
var jsonCallback = urlObj.query["callback"];

This works fine, but it fails when one of the parameters contains an apostrophe. It looks like it stops parsing the query string in an apostrophe. Here, what console.log prints for two different request objects:

{ callback: 'jQuery15105242477038409561_1304925579219',
  id: '6c91c74db064c93f1f020000',
  artist: 'Radiohead',
  title: 'Everything In Its Right Place',
  album: 'Kid A',
  filename: '01 Everything In Its Right Place.m4a',
  user: 'Cowrelish',
  userId: '82a89b4df7a9120305000000',
  room: 'qwantz',
  timestamp: '1304924972555',
  _: '1304925611362' }
{ callback: 'jQuery15105242477038409561_1304925579221',
  id: '798cc74dfcce4337f7010000',
  artist: 'Toy Dolls',
  title: 'The Final Countdown',
  album: 'HOLY SHIT!!! IT' }

The album for the second is “HOLY SHIT !! IT FINAL COUNTDOWN!”, As you can see that it was truncated during the apostrophe.

I tried to elude the apostrophe in the client code, but all I get is the "album:" HOLY SHIT !!! IT \\ ". It escapes the slash, but not the apostrophe.

? - Node.js?

+3
1

jquery, node ( , ).

node 0.4.7.

:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
  $(document).ready(function () {
    $.getJSON('/', {test:"it a test"});
  });
</script>

node, :

console.log(require('url').parse(req.url, true));

:

{ test: 'it\ a test' }

, jQuery, node.

URL- ? node - , :

require('url').parse('http://www.example.org/?q=it\ working', true);

- -, URL-?

+2
source

All Articles