SchmoX
SchmoX

Reputation: 23

How does % function that is used in a Path

I am setting up a PKI with a script but I have some lines here that I don't understand how it works

Script uses in some paths for example "http://pseudo.domain.org/%3%8%9.crl" .

But the script creates this file with a real name for example pseudo domain.crl

How exactly does the %3%8%9.crl etc become the file name?

Thanks in advance

Upvotes: 2

Views: 75

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174485

The escape sequence %XX (where X are hexadecimal digits) is known as percent-encoding or URL encoding.

In a URI, some characters, like : or / or @ for example, have special syntactical meaning, and so they need to be escaped if passed as part of a path.

You can manually escape parts of a URI string with [uri]::EscapeDataString():

PS C:\> $path = "uri-stem-with-a-@-in-it"
PS C:\> [uri]::EscapeDataString($path)
uri-stem-with-a-%40-in-it

To decode an encoded string, use [uri]::UnescapeDataString():

PS C:\> [uri]::UnescapeDataString("%41%42%43")
ABC

Upvotes: 2

Related Questions