FAQ
Hi,

I'm trying to parse a utf-8 url, but the url.parse function doesn't
seem to like spaces.

var url = require("url");
var file_url = "http://myhost.nl:9090/some/path/myweirdfile æfqúsß.mp3";
console.log("parsed:" , url.parse(file_url));

This gives the following output:

parse: { protocol: 'http:',
slashes: true,
host: 'myhost.nl:9090',
port: '9090',
hostname: 'myhost.nl',
href: 'http://myhost.nl:9090/some/path/myweirdfile',
pathname: '/some/path/myweirdfile',
path: '/some/path/myweirdfile'
}

Where exactly do I need to tackle this and how?

Thijs

--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Search Discussions

  • Matt at May 15, 2012 at 4:24 pm
    Spaces are encoded as a + in URLs.
    On Tue, May 15, 2012 at 11:58 AM, Thijs Koerselman wrote:

    Hi,

    I'm trying to parse a utf-8 url, but the url.parse function doesn't
    seem to like spaces.

    var url = require("url");
    var file_url = "http://myhost.nl:9090/some/path/myweirdfile æfqúsß.mp3";
    console.log("parsed:" , url.parse(file_url));

    This gives the following output:

    parse: { protocol: 'http:',
    slashes: true,
    host: 'myhost.nl:9090',
    port: '9090',
    hostname: 'myhost.nl',
    href: 'http://myhost.nl:9090/some/path/myweirdfile',
    pathname: '/some/path/myweirdfile',
    path: '/some/path/myweirdfile'
    }

    Where exactly do I need to tackle this and how?

    Thijs

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Felipe Gasper at May 15, 2012 at 4:48 pm
    puny code?

    Thijs Koerselman wrote:
    Hi,

    I'm trying to parse a utf-8 url, but the url.parse function doesn't
    seem to like spaces.

    var url = require("url");
    var file_url = "http://myhost.nl:9090/some/path/myweirdfile
    æfqúsß.mp3";
    console.log("parsed:" , url.parse(file_url));

    This gives the following output:

    parse: { protocol: 'http:',
    slashes: true,
    host: 'myhost.nl:9090',
    port: '9090',
    hostname: 'myhost.nl',
    href: 'http://myhost.nl:9090/some/path/myweirdfile',
    pathname: '/some/path/myweirdfile',
    path: '/some/path/myweirdfile'
    }

    Where exactly do I need to tackle this and how?

    Thijs

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Sent from my Android phone with K-9 Mail. Please excuse my brevity.

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Isaac Schlueter at May 15, 2012 at 6:08 pm
    The URL parser doesn't parse spaces.

    It would be good to maybe discuss this, as it's a common complaint.

    Let's discuss it in this issue: https://github.com/joyent/node/issues/3270

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Thijs Koerselman at May 15, 2012 at 10:30 pm

    On Tue, May 15, 2012 at 8:08 PM, Isaac Schlueter wrote:
    The URL parser doesn't parse spaces.

    It would be good to maybe discuss this, as it's a common complaint.

    Let's discuss it in this issue: https://github.com/joyent/node/issues/3270
    Thanks Isaac. That discussion makes it clear. I'm all for. I will just
    escape the spaces myself for now but it would be great if this is
    handled in url.parse. I would like to be able to retrieve the filename
    from the parsed data as it is, with spaces and all.

    Cheers,
    Thijs

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Isaac Schlueter at May 16, 2012 at 12:44 am
    Thijs,

    Well, if we do this, you'll get it with the spaces converted to %20.
    It'll be up to you to call decodeURIComponent on it.

    Spaces are actually not allowed in URLs, after all.

    On Tue, May 15, 2012 at 3:30 PM, Thijs Koerselman
    wrote:
    On Tue, May 15, 2012 at 8:08 PM, Isaac Schlueter wrote:
    The URL parser doesn't parse spaces.

    It would be good to maybe discuss this, as it's a common complaint.

    Let's discuss it in this issue: https://github.com/joyent/node/issues/3270
    Thanks Isaac. That discussion makes it clear. I'm all for. I will just
    escape the spaces myself for now but it would be great if this is
    handled in url.parse. I would like to be able to retrieve the filename
    from the parsed data as it is, with spaces and all.

    Cheers,
    Thijs

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Matt at May 16, 2012 at 3:15 am
    Another argument for a parsed_path value. Though again we have to realise
    that comes with an overhead, which is worth considering.
    On Tue, May 15, 2012 at 8:44 PM, Isaac Schlueter wrote:

    Thijs,

    Well, if we do this, you'll get it with the spaces converted to %20.
    It'll be up to you to call decodeURIComponent on it.

    Spaces are actually not allowed in URLs, after all.

    On Tue, May 15, 2012 at 3:30 PM, Thijs Koerselman
    wrote:
    On Tue, May 15, 2012 at 8:08 PM, Isaac Schlueter wrote:
    The URL parser doesn't parse spaces.

    It would be good to maybe discuss this, as it's a common complaint.

    Let's discuss it in this issue:
    https://github.com/joyent/node/issues/3270
    Thanks Isaac. That discussion makes it clear. I'm all for. I will just
    escape the spaces myself for now but it would be great if this is
    handled in url.parse. I would like to be able to retrieve the filename
    from the parsed data as it is, with spaces and all.

    Cheers,
    Thijs

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Thijs Koerselman at May 16, 2012 at 12:14 pm
    Hi Isaac,
    Well, if we do this, you'll get it with the spaces converted to %20.
    It'll be up to you to call decodeURIComponent on it.

    Spaces are actually not allowed in URLs, after all.
    Yep that's all fine with me. At least I don't have to replace the " "
    with "%20" manually before using the url.

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Isaac Schlueter at May 16, 2012 at 11:36 pm
    Landed on 9fc7283a403bb0dec096b76991226cba8e7b73c2 in master.

    On Wed, May 16, 2012 at 5:13 AM, Thijs Koerselman
    wrote:
    Hi Isaac,
    Well, if we do this, you'll get it with the spaces converted to %20.
    It'll be up to you to call decodeURIComponent on it.

    Spaces are actually not allowed in URLs, after all.
    Yep that's all fine with me. At least I don't have to replace the " "
    with "%20" manually before using the url.

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupnodejs @
categoriesnodejs
postedMay 15, '12 at 3:58p
activeMay 16, '12 at 11:36p
posts9
users4
websitenodejs.org
irc#node.js

People

Translate

site design / logo © 2022 Grokbase