Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommended way to encode/decode URLs [duplicate]

Tags:

escaping

go

Possible Duplicate:
Encode / decode URLs

What's the recommended way to encode/decode URLs in Go? I am looking to the equivalent of encodeURIComponent in JavaScript.

like image 987
Sergi Mansilla Avatar asked Dec 11 '12 19:12

Sergi Mansilla


People also ask

What is the best way to URL encode a string?

In JavaScript, PHP, and ASP there are functions that can be used to URL encode a string. PHP has the rawurlencode() function, and ASP has the Server. URLEncode() function. In JavaScript you can use the encodeURIComponent() function.

Should I encode URLs?

Why do we need to encode? URLs can only have certain characters from the standard 128 character ASCII set. Reserved characters that do not belong to this set must be encoded. This means that we need to encode these characters when passing into a URL.

What is double URL encoding?

Double URI-encoding is a special type of double encoding in which data is URI-encoded twice in a row. It has been used to bypass authorization schemes and security filters against code injection, directory traversal, Cross-site scripting (XSS) and SQL injection.

How do you encode a URL?

If a URL contains characters outside the ASCII set, the URL has to be converted. URL encoding converts non-ASCII characters into a format that can be transmitted over the Internet. URL encoding replaces non-ASCII characters with a "%" followed by hexadecimal digits. URLs cannot contain spaces.


1 Answers

You're looking for the "net/url" package.

http://golang.org/pkg/net/url/#QueryEscape

like image 179
Daniel Avatar answered Oct 01 '22 12:10

Daniel