TeraTech/MMM-WiFiPassword

Special Character Support?

Opened this issue · 3 comments

//TODO: Allow for special characters
this.qrText = "WIFI:" +
"T:" + this.auth +
";S:" + this.config.network +
";P:" + this.config.password +
";H:" + this.config.hiddenId +
";";

Hello! I was wanting to ask about special character support, and potentially even help create the change. I just am not sure which characters specifically need to be fixed for QR codes. I believe the change would be to send the strings to functions that escape and return the escaped character versions in the lines here?

If you can provide a list of the characters or documentation to find the characters to concern ourselves with, then I can assist in adding this capability.

I found the following here that seems to match what we would need: https://github.com/zxing/zxing/wiki/Barcode-Contents#wi-fi-network-config-android-ios-11

Special characters , ;, ,, " and : should be escaped with a backslash () as in MECARD encoding. For example, if an SSID was literally "foo;bar\baz" (with double quotes part of the SSID name itself) then it would be encoded like: WIFI:S:"foo;bar\baz";;

I tried making a little function and in my testing I think we will always have issues with the backslash () because it gets dropped when interpretting a string in Javascript unless the string was created with String.raw with backticks, which are particularly annoying in Github to show without it making it code.

but the rest should be able to be escaped easily:

  escapeSpecialCharacters: function(str) {
	return str.split(String.fromCharCode(92)).join('\\\\')  //-- If it were to work, this is how backslashes is best found and replaced.
		.replaceAll(/;/g,'\\;')
		.replaceAll(/,/g,'\\,')
		.replaceAll(/"/g,'\\"')
		.replaceAll(/:/g,'\\:')
	;
  },

Hi @kenman345, sorry it took so long for me to respond. I made this app a few years ago and never expected to have so many others interested in it! I barely have time to work on this anymore, but there are others who have forked this code and are making improvements to it all the time.

I'll be glad to incorporate this but I don't have the ability to peer review this. If someone can review this and do a PR, I'll merge it in.

Wow, I forgot about this and honestly feel like I sound way smarter in this than I am now.

I'll try and get a PR worked up for this but definitely would love someone reviewing it as well