What is the logic of url decoder when using double quotes?

Why url decoder doesn't get error decoding% 22. This is a double quote. When a programmer types a double quote in a string syntactically, they must use two double quotation marks "" to represent the double quote.

Example

string myString = "It\"s nice to meet you"; console.write(myString); 

Output

Nice to meet you

But when url decrypts double quotes, why doesn't it break. After the string is passed through the url decoder, there is only one quote. Why does this not break the code?

Example

  string myString = "It%22s nice to meet you"; myString = HttpUtility.UrlDecode(myString); console.Write(myString); 

Output

Nice to meet you

+5
source share
2 answers

The need to escape from double quotes is just a problem for literals in C #. Language is defined in this way. Non-literals do not affect: ((char)35).ToString() == "\"" true.

This does not affect the actual runtime values. "\"".Length is 1. The CLR does not know about escaping.

CLR is able to host many programming languages. He does not care about the screening rules of one language.

Library functions cannot even tell how you wrote or calculated a string. Even if they wanted to.

+4
source

The results are the same. These are just different representations of the double quote - depending on how you decode it.

 // All the same: string myString1 = @"It""s nice to meet you"; // string simplification string myString2 = "It\"s nice to meet you"; // escaping a double quote string myString3 = HttpUtility.UrlDecode("It%22s nice to meet you"); 
+1
source

Source: https://habr.com/ru/post/1245518/


All Articles