Community discussions

MikroTik App
 
jeroenp
Member Candidate
Member Candidate
Topic Author
Posts: 159
Joined: Mon Mar 17, 2014 11:30 am
Location: Amsterdam
Contact:

[SOLVED] Anyone having a stringify function circumventing :put to displaying un-printable characters as HEX escapes?

Thu May 05, 2016 2:35 pm

While researching Why does `get` for static DNS and DHCP leases have issues with nulls in string values and how can I work around it? I think I found the culprit:

`:put` won't HEX-escape the characters it cannot print. Some examples are below.

JavaScript has a JSON.stringify for this (example at http://stackoverflow.com/questions/2167 ... 2#21672392)

Is there such a function for the Scripting engine?
:put "a\00b"
ab
:put "a\01b" 
ab
:put "a\02b" 
ab
:put "a\03b" 
ab
:put "a\04b" 
ab
:put "a\05b" 
ab
:put "a\06b" 
ab
:put "a\07b" 
ab
:put "a\08b" 
b
:put "a\09b" 
a	b
:put "a\10b"  
ab
:put "a\11b" 
ab
:put "a\12b" 
ab
:put "a\13b" 
ab
:put "a\14b" 
ab
:put "a\15b" 
ab
:put "a\16b" 
ab
:put "a\17b" 
ab
:put "a\18b" 
ab
:put "a\19b" 
ab
:put "a\20b"  
a b
:put "a\FFb"  
a?b
:put "a\FEb"  
a?b
:put "a\FDb" 
a?b
:put "a\F0b" 
a?b
:put "a\E0b" 
a?b
:put "a\D0b" 
a?b
:put "a\C0b" 
a?b
:put "a\B0b" 
a?b
:put "a\A0b" 
a?b
:put "a\90b" 
a?b
:put "a\80b" 
a?b
:put "a\70b" 
apb
Last edited by jeroenp on Tue May 10, 2016 11:02 am, edited 2 times in total.
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Anyone having a `stringify` function to circumvent `:put` not displaying un-printable characters as HEX escapes?

Thu May 05, 2016 3:15 pm

Nope.

If you actually make one, and ask MikroTik for a wiki account, I'm sure they'll make you one, at which point you can add it to the wiki.


I've been meaning to make something similar (more akin to PHP's var_dump()), but I've only ever gotten half way through, and didn't even considered unprintable characters. I'd love to have such a function, as I've been needing it myself on multiple occasions.
 
jeroenp
Member Candidate
Member Candidate
Topic Author
Posts: 159
Joined: Mon Mar 17, 2014 11:30 am
Location: Amsterdam
Contact:

Re: Anyone having a `stringify` function to circumvent `:put` not displaying un-printable characters as HEX escapes?

Thu May 05, 2016 3:21 pm

...
Thanks. Let me know what you have so I can extend.

This is a start: https://gist.github.com/jpluimers/f667a ... f1eeda2c2f