Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String containing special character converted to escaped representation on Android - how to prevent this?

In my home network I have a service with the name "Den TV" with a space between "Den" and "TV".

When I resolve this service using NSD Manager on my mobile, I get the service name using NsdServiceInfo.getServiceName() and log it. I also create an object that wraps the NsdServiceInfo object and add it to an ArrayAdapter for a ListView.

Both the log message and the list view display the string "Den\\032TV". It looks like the space has been substituted with a "substitute" character (value 26 or octal 032), and that the string has then been escaped to "Den\032TV" and then further escaped to "Den\\032TV".

To me this is really bizarre behaviour. Why is NSD Manager not returning the string "as is". Avahi has no problems with it. And even if the space is being substituted for some reason I cannot fathom, why is then being escaped? Twice?

Also note that the space character has value 32, so that maybe it's not an octal value, but then why the preceding "0"?

Can anyone help me figure out how to get the real value?

like image 524
AlastairG Avatar asked Oct 20 '22 09:10

AlastairG


1 Answers

According to http://www.ietf.org/rfc/rfc6763.txt.
Note that nslookup escapes spaces as "\032" for display purposes, but a graphical DNS-SD browser should not. so "\032" is no java escape character and protocol specific.

like image 171
user3618876 Avatar answered Oct 23 '22 00:10

user3618876