Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 258531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:11:18+00:00 2026-05-11T22:11:18+00:00

Are there any equivalent JavaScript functions for Python’s urllib.parse.quote() and urllib.parse.unquote() ? The closest

  • 0

Are there any equivalent JavaScript functions for Python’s urllib.parse.quote() and urllib.parse.unquote()?

The closest I’ve come across are encodeURI()/encodeURIComponent() and escape() (and their corresponding un-encoding functions), but they don’t encode/decode the same set of special characters as far as I can tell.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T22:11:18+00:00Added an answer on May 11, 2026 at 10:11 pm

    OK, I think I’m going to go with a hybrid custom set of functions:

    Encode: Use encodeURIComponent(), then put slashes back in.
    Decode: Decode any %hex values found.

    Here’s a more complete variant of what I ended up using (it handles Unicode properly, too):

    function quoteUrl(url, safe) {
        if (typeof(safe) !== 'string') {
            safe = '/';    // Don't escape slashes by default
        }
    
        url = encodeURIComponent(url);
    
        // Unescape characters that were in the safe list
        toUnencode = [  ];
        for (var i = safe.length - 1; i >= 0; --i) {
            var encoded = encodeURIComponent(safe[i]);
            if (encoded !== safe.charAt(i)) {    // Ignore safe char if it wasn't escaped
                toUnencode.push(encoded);
            }
        }
    
        url = url.replace(new RegExp(toUnencode.join('|'), 'ig'), decodeURIComponent);
    
        return url;
    }
    
    
    var unquoteUrl = decodeURIComponent;    // Make alias to have symmetric function names
    

    Note that if you don’t need “safe” characters when encoding ('/' by default in Python), then you can just use the built-in encodeURIComponent() and decodeURIComponent() functions directly.

    Also, if there are Unicode characters (i.e. characters with codepoint >= 128) in the string, then to maintain compatibility with JavaScript’s encodeURIComponent(), the Python quote_url() would have to be:

    def quote_url(url, safe):
        """URL-encodes a string (either str (i.e. ASCII) or unicode);
        uses de-facto UTF-8 encoding to handle Unicode codepoints in given string.
        """
        return urllib.quote(unicode(url).encode('utf-8'), safe)
    

    And unquote_url() would be:

    def unquote_url(url):
        """Decodes a URL that was encoded using quote_url.
        Returns a unicode instance.
        """
        return urllib.unquote(url).decode('utf-8')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 151k
  • Answers 151k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use the toArray() method of the ArrayList class and pass… May 12, 2026 at 10:00 am
  • Editorial Team
    Editorial Team added an answer I ended up running Nginx with Passenger and Ruby 1.9… May 12, 2026 at 10:00 am
  • Editorial Team
    Editorial Team added an answer Don't use regular expressions for working on xml. Xml is… May 12, 2026 at 10:00 am

Related Questions

Are there any equivalent JavaScript functions for Python's urllib.parse.quote() and urllib.parse.unquote() ? The closest
Challenge Here is the challenge (of my own invention, though I wouldn't be surprised
A strict equality operator will tell you if two object types are equal. However,
Are there any open-source compression/decomp libraries available for Ruby? Has anyone implemented LZW? Or,
Are there any ways providing an alternate GIF/PNG image, in case the user has

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.