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

  • SEARCH
  • Home
  • 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

Related Questions

Is there any Ruby equivalent for Python's builtin zip function? If not, what is
Are there any nvl() equivalent functions in SQL? Or something close enough to be
Is there any shortcut to accomplishing the equivalent of PHP's array_flip function in JavaScript
I know semilogx and semilogy for 2D plots. There is any equivalent for SURF
Is there any function in c# equivalent to C's stdio function ungetc() ?
Is there any javascript function that can encrypt data: For example i want to
is there any equivalent to FacesContext, but in servlet environment? I have some DAOSessionManager
Is there any method to captitalize a string in JavaScript? I want a JS
From my research it looks like Javascript's regular expressions don't have any built-in equivalent
Is there any equivalent to MySQL's SHOW CREATE TABLE <tablename> in informix? I would

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.