Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

asp.net

Why does url decode not get an error when it decodes %22. This is a double quote. When a programmer enters a double quote in a string syntactically they must use two double quotes "" to represent a double quote.

For Example

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

Output

It"s nice to meet you

But when url decodes a double quotes why does it not break. After the string is passed through the url decoder there is only a single quote ". Why does this not break the code?

For Example

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

Output

It"s nice to meet you

like image 383
Leslie Jones Avatar asked Mar 21 '16 23:03

Leslie Jones


1 Answers

The need to escape double quotes is only a concern for literal strings in C#. The language is defined that way. Non-literals are not impacted: ((char)35).ToString() == "\"" is true.

This has no impact on the actual runtime values. "\"".Length is 1. The CLR is not aware of the escaping.

The CLR is capable of hosting many programming languages. It does not care about the escaping rules of a single language.

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

like image 61
usr Avatar answered Sep 21 '22 05:09

usr