Erroneous string format using mosquitto_sub/_pub
See original GitHub issueSteps to reproduce
Run the following *.ps1 script in a text file with UTF-8 ecoding:
while ($true)
{
$date = Get-Date -Format "o"
$rand = Get-Random -Minimum -10 -Maximum 40
$message = '{"time":' + '"' + "$date" + '"' + ', "value":' + "$rand" + ', "label":"ºC"}'
#echo "$message"
mosquitto_pub -h test.mosquitto.org -t tofol/test -m "$message"
Start-Sleep -s 1
}
Now in another terminal window, subscribe to the mosquitto topic:
mosquitto_sub -h test.mosquitto.org -t tofol/test
The output is unexpected:
{time:2021-03-30T12:30:24.0266957+02:00, value:3, label:║C}
Expected behavior
Expected behavior is seem by running the following script:
while ($true)
{
$date = Get-Date -Format "o"
$rand = Get-Random -Minimum -10 -Maximum 40
$message = '{"time":' + '"' + "$date" + '"' + ', "value":' + "$rand" + ', "label":"ºC"}'
echo "$message"
#mosquitto_pub -h test.mosquitto.org -t tofol/test -m "$message"
Start-Sleep -s 1
}
This outputs:
{"time":"2021-03-30T12:31:48.2728626+02:00", "value":33, "label":"ºC"}
Environment data
Name Value
---- -----
PSVersion 7.1.3
PSEdition Core
GitCommitId 7.1.3
OS Microsoft Windows 10.0.19041
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:36 (20 by maintainers)
Top Results From Across the Web
String.format is creating error - java
This only happened when I use String.format() , When I was using StringBuilder to return in the toString method, the codes run just...
Read more >error ring "format into string" - NI Community
I'm not sure how the "Error Code Database.vi" is organized, but I suspect the database lookups are what drags it into the mud...
Read more >Format string attack
The Format String exploit occurs when the submitted data of an input string is evaluated as a command by the application. In this...
Read more >StringFormatMatches: String.format string doesn't match ...
Id. StringFormatMatches ; Summary. String.format string doesn't match the XML format string ; Severity. Error ; Category. Correctness: Messages ; Platform. Android.
Read more >stringFormat error Perspective - Ignition
Hi, I want to copy my labels into an email and I want to transfer integer into string, so I used stringFormat. However,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
My pleasure, @chris-steema; I certainly learned a few things myself.
Good point. I’ll see if I can find anything. Thanks.
Yes, the conversion of byte streams to .NET strings I can imagine very clearly. Great stuff, thanks to your patient explanations I think I now have a pretty clear idea of what’s going on. Powershell’s inability to escape embedded quotes was a red herring for me, as I had imagined that that and what turned out to be an encoding issue were related, which they aren’t. As far as I’m concerned we can close this issue, but I won’t do so now just in case you’d prefer to keep it open for whatever reason.