Re: [WebDNA] Escaping content for JSON

This WebDNA talk-list message is from

2016


It keeps the original formatting.
numero = 113232
interpreted = N
texte = 820 --Apple-Mail=_8AC1B9C6-46C4-4D78-B6A6-F1327C9133AF Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Nice Tom. Thanks for sharing :) Kind regards Stuart Tremain Pharoah Lane Software AUSTRALIA webdna@idfk.com.au > On 28 Nov. 2016, at 08:04, Tom Duke wrote: >=20 > Hi all, >=20 > Re-visting this as I am doing a lot of work involving JSON and = Javascript and escaping strings was doing my head in. >=20 > These functions work and only require one [convertchars] pass. Thanks = to the write up by Brian and Terry here - = http://www.webdna.us/page.dna?numero=3D183 = - which outlined that both = the from, and to fields are first [unurl]'d when using convert chars. >=20 > It might help someone else. >=20 > - Tom >=20 >=20 >=20 > Ref:=20 > = http://stackoverflow.com/questions/983451/where-can-i-find-a-list-of-escap= e-characters-required-for-my-json-ajax-return-tyd = > https://en.wikipedia.org/wiki/UTF-8#Codepage_layout = >=20 >=20 >=20 > [function name=3Djson_escape][!] >=20 > Note Char Hex Stored in WebDNA As > Quote " %22 " > BackSlash \ %5C \ > ForwardSlash / / / > Form Feed %08 %08 > Line Feed %0A %0B > Carriage Return %0D %0B > Horizontal Tab %09 %1D >=20 > %0B and %1D added to convert data read from a WebDNA db >=20 > [/!][table name=3DtabJSONESCAPE&fields=3Dfrom,to] > %22\%22 > %5C\%5C > /\/ > %08\b > %0C\f > %0A\n > %0D\r > %09\t > %0B\n > %1D\t > [/table][!] > [/!][return][convertchars = table=3DtabJSONESCAPE][params_string][/convertchars][/return][!] > [/!][/function] >=20 > [text]test_string=3DL "John" & \ / Joanna ' + Jane[/text] >=20 > [json_escape [test_string]] >=20 > Result: L \"John\" & \\ \/ Joanna ' + Jane >=20 >=20 >=20 > [function name=3Djs_escape][!] >=20 > Note Char Hex Stored in WebDNA As > Quote " %22 " > Apostraphe ' %27 ' > BackSlash \ %5C \ > ForwardSlash / / / > Form Feed %08 %08 > Line Feed %0A %0B > Carriage Return %0D %0B > Horizontal Tab %09 %1D >=20 > %0B and %1D added to convert data read from a WebDNA db >=20 > [/!][table name=3DtabJSESCAPE&fields=3Dfrom,to] > %22\%22 > %27\%27 > %5C\%5C > /\/ > %08\b > %0C\f > %0A\n > %0D\r > %09\t > %0B\n > %1D\t > [/table][!] > [/!][return][convertchars = table=3DtabJSESCAPE][params_string][/convertchars][/return][!] > [/!][/function] >=20 > [text]test_string=3DL "John" & \ / Joanna ' + Jane[/text] >=20 > [js_escape [test_string]] >=20 > Result: L \"John\" & \\ \/ Joanna \' + Jane >=20 >=20 > --------------------------------------------------------- This message = is sent to you because you are subscribed to the mailing list . To = unsubscribe, E-mail to: archives: = http://mail.webdna.us/list/talk@webdna.us Bug Reporting: = support@webdna.us --Apple-Mail=_8AC1B9C6-46C4-4D78-B6A6-F1327C9133AF Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii Nice Tom.

Thanks for sharing :)


Kind regards

Stuart Tremain
Pharoah Lane Software
AUSTRALIA






On 28 Nov. 2016, at 08:04, Tom Duke <tom@revolutionaries.ie> wrote:

Hi all,

Re-visting this as I am doing a lot of work = involving JSON and Javascript and escaping strings was doing my head = in.

These functions work and only require one = [convertchars] pass.  Thanks to the write up by Brian and Terry = here - http://www.webdna.us/page.dna?numero=3D183 - which = outlined that both the from, and to fields are first [unurl]'d when = using convert chars.

It might help someone = else.

- Tom



Ref: 
http://stackoverflow.com/questions/983451/where-can-i-find-a-li= st-of-escape-characters-required-for-my-json-ajax-return-tyd
=



[function name=3Djson_escape][!]

= Note            Char     = Hex     Stored in WebDNA As
= Quote           "       =  %22     "
= BackSlash       \        %5C =     \
= ForwardSlash    /        /   =     /
= Form Feed               =  %08     %08
= Line Feed               =  %0A     %0B
= Carriage Return          %0D   =   %0B
Horizontal Tab     =       %09     %1D

= %0B and %1D added to convert data read from a WebDNA db

[/!][table = name=3DtabJSONESCAPE&fields=3Dfrom,to]
%22\%22
%5C\%5C
/\/
%08\b
%0C\f
%0A\n
%0D\r
%09\t
%0B\n
%1D\t
[/table][!]
= [/!][return][convertchars = table=3DtabJSONESCAPE][params_string][/convertchars][/return][!]
[/!][/function]

[text]test_string=3DL "John" & \  / Joanna ' + = Jane[/text]

[json_escape [test_string]]

Result: L \"John\" & \\ \/ = Joanna ' + Jane



[function name=3Djs_escape][!]

= Note            Char     = Hex     Stored in WebDNA As
= Quote           "       =  %22     "
= Apostraphe      '       =             %27   =   '
= BackSlash       \        %5C =     \
= ForwardSlash    /        /   =     /
= Form Feed               =  %08     %08
= Line Feed               =  %0A     %0B
= Carriage Return          %0D   =   %0B
Horizontal Tab     =       %09     %1D

= %0B and %1D added to convert data read from a WebDNA db

[/!][table = name=3DtabJSESCAPE&fields=3Dfrom,to]
%22\%22
%27\%27
%5C\%5C
/\/
%08\b
%0C\f
%0A\n
%0D\r
%09\t
%0B\n
%1D\t
[/table][!]
= [/!][return][convertchars = table=3DtabJSESCAPE][params_string][/convertchars][/return][!]
[/!][/function]

[text]test_string=3DL "John" & \  / Joanna ' + = Jane[/text]

[js_escape [test_string]]

Result: L \"John\" & \\ \/ = Joanna \' + Jane


--------------------------------------------------------- This message is sent to you because you are subscribed to the mailing list . To unsubscribe, E-mail to: archives: http://mail.webdna.us/list/talk@webdna.us Bug Reporting: support@webdna.us

= --------------------------------------------------------- This message is sent to you because you are subscribed to the mailing list . To unsubscribe, E-mail to: archives: http://mail.webdna.us/list/talk@webdna.us Bug Reporting: support@webdna.us --Apple-Mail=_8AC1B9C6-46C4-4D78-B6A6-F1327C9133AF-- . Associated Messages, from the most recent to the oldest:

    
  1. Re: [WebDNA] Escaping content for JSON (Stuart Tremain 2016)
  2. Re: [WebDNA] Escaping content for JSON (Tom Duke 2016)
  3. Re: [WebDNA] Escaping content for JSON (Tom Duke 2013)
  4. Re: [WebDNA] Escaping content for JSON (Donovan Brooke 2013)
  5. [WebDNA] Escaping content for JSON (Tom Duke 2013)
820 --Apple-Mail=_8AC1B9C6-46C4-4D78-B6A6-F1327C9133AF Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Nice Tom. Thanks for sharing :) Kind regards Stuart Tremain Pharoah Lane Software AUSTRALIA webdna@idfk.com.au > On 28 Nov. 2016, at 08:04, Tom Duke wrote: >=20 > Hi all, >=20 > Re-visting this as I am doing a lot of work involving JSON and = Javascript and escaping strings was doing my head in. >=20 > These functions work and only require one [convertchars] pass. Thanks = to the write up by Brian and Terry here - = http://www.webdna.us/page.dna?numero=3D183 = - which outlined that both = the from, and to fields are first [unurl]'d when using convert chars. >=20 > It might help someone else. >=20 > - Tom >=20 >=20 >=20 > Ref:=20 > = http://stackoverflow.com/questions/983451/where-can-i-find-a-list-of-escap= e-characters-required-for-my-json-ajax-return-tyd = > https://en.wikipedia.org/wiki/UTF-8#Codepage_layout = >=20 >=20 >=20 > [function name=3Djson_escape][!] >=20 > Note Char Hex Stored in WebDNA As > Quote " %22 " > BackSlash \ %5C \ > ForwardSlash / / / > Form Feed %08 %08 > Line Feed %0A %0B > Carriage Return %0D %0B > Horizontal Tab %09 %1D >=20 > %0B and %1D added to convert data read from a WebDNA db >=20 > [/!][table name=3DtabJSONESCAPE&fields=3Dfrom,to] > %22\%22 > %5C\%5C > /\/ > %08\b > %0C\f > %0A\n > %0D\r > %09\t > %0B\n > %1D\t > [/table][!] > [/!][return][convertchars = table=3DtabJSONESCAPE][params_string][/convertchars][/return][!] > [/!][/function] >=20 > [text]test_string=3DL "John" & \ / Joanna ' + Jane[/text] >=20 > [json_escape [test_string]] >=20 > Result: L \"John\" & \\ \/ Joanna ' + Jane >=20 >=20 >=20 > [function name=3Djs_escape][!] >=20 > Note Char Hex Stored in WebDNA As > Quote " %22 " > Apostraphe ' %27 ' > BackSlash \ %5C \ > ForwardSlash / / / > Form Feed %08 %08 > Line Feed %0A %0B > Carriage Return %0D %0B > Horizontal Tab %09 %1D >=20 > %0B and %1D added to convert data read from a WebDNA db >=20 > [/!][table name=3DtabJSESCAPE&fields=3Dfrom,to] > %22\%22 > %27\%27 > %5C\%5C > /\/ > %08\b > %0C\f > %0A\n > %0D\r > %09\t > %0B\n > %1D\t > [/table][!] > [/!][return][convertchars = table=3DtabJSESCAPE][params_string][/convertchars][/return][!] > [/!][/function] >=20 > [text]test_string=3DL "John" & \ / Joanna ' + Jane[/text] >=20 > [js_escape [test_string]] >=20 > Result: L \"John\" & \\ \/ Joanna \' + Jane >=20 >=20 > --------------------------------------------------------- This message = is sent to you because you are subscribed to the mailing list . To = unsubscribe, E-mail to: archives: = http://mail.webdna.us/list/talk@webdna.us Bug Reporting: = support@webdna.us --Apple-Mail=_8AC1B9C6-46C4-4D78-B6A6-F1327C9133AF Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii Nice Tom.

Thanks for sharing :)


Kind regards

Stuart Tremain
Pharoah Lane Software
AUSTRALIA






On 28 Nov. 2016, at 08:04, Tom Duke <tom@revolutionaries.ie> wrote:

Hi all,

Re-visting this as I am doing a lot of work = involving JSON and Javascript and escaping strings was doing my head = in.

These functions work and only require one = [convertchars] pass.  Thanks to the write up by Brian and Terry = here - http://www.webdna.us/page.dna?numero=3D183 - which = outlined that both the from, and to fields are first [unurl]'d when = using convert chars.

It might help someone = else.

- Tom



Ref: 
http://stackoverflow.com/questions/983451/where-can-i-find-a-li= st-of-escape-characters-required-for-my-json-ajax-return-tyd
=



[function name=3Djson_escape][!]

= Note            Char     = Hex     Stored in WebDNA As
= Quote           "       =  %22     "
= BackSlash       \        %5C =     \
= ForwardSlash    /        /   =     /
= Form Feed               =  %08     %08
= Line Feed               =  %0A     %0B
= Carriage Return          %0D   =   %0B
Horizontal Tab     =       %09     %1D

= %0B and %1D added to convert data read from a WebDNA db

[/!][table = name=3DtabJSONESCAPE&fields=3Dfrom,to]
%22\%22
%5C\%5C
/\/
%08\b
%0C\f
%0A\n
%0D\r
%09\t
%0B\n
%1D\t
[/table][!]
= [/!][return][convertchars = table=3DtabJSONESCAPE][params_string][/convertchars][/return][!]
[/!][/function]

[text]test_string=3DL "John" & \  / Joanna ' + = Jane[/text]

[json_escape [test_string]]

Result: L \"John\" & \\ \/ = Joanna ' + Jane



[function name=3Djs_escape][!]

= Note            Char     = Hex     Stored in WebDNA As
= Quote           "       =  %22     "
= Apostraphe      '       =             %27   =   '
= BackSlash       \        %5C =     \
= ForwardSlash    /        /   =     /
= Form Feed               =  %08     %08
= Line Feed               =  %0A     %0B
= Carriage Return          %0D   =   %0B
Horizontal Tab     =       %09     %1D

= %0B and %1D added to convert data read from a WebDNA db

[/!][table = name=3DtabJSESCAPE&fields=3Dfrom,to]
%22\%22
%27\%27
%5C\%5C
/\/
%08\b
%0C\f
%0A\n
%0D\r
%09\t
%0B\n
%1D\t
[/table][!]
= [/!][return][convertchars = table=3DtabJSESCAPE][params_string][/convertchars][/return][!]
[/!][/function]

[text]test_string=3DL "John" & \  / Joanna ' + = Jane[/text]

[js_escape [test_string]]

Result: L \"John\" & \\ \/ = Joanna \' + Jane


--------------------------------------------------------- This message is sent to you because you are subscribed to the mailing list . To unsubscribe, E-mail to: archives: http://mail.webdna.us/list/talk@webdna.us Bug Reporting: support@webdna.us

= --------------------------------------------------------- This message is sent to you because you are subscribed to the mailing list . To unsubscribe, E-mail to: archives: http://mail.webdna.us/list/talk@webdna.us Bug Reporting: support@webdna.us --Apple-Mail=_8AC1B9C6-46C4-4D78-B6A6-F1327C9133AF-- . Stuart Tremain

DOWNLOAD WEBDNA NOW!

Top Articles:

Talk List

The WebDNA community talk-list is the best place to get some help: several hundred extremely proficient programmers with an excellent knowledge of WebDNA and an excellent spirit will deliver all the tips and tricks you can imagine...

Related Readings:

Calculating Age from DB fields (2003) Problem displaying search result (1997) Date search - yes or no (1997) [date] for today's date, while inside old order file (1998) Re:quit command on NT (1997) WebCat virtual postcard is done! Thanks for the help! (1998) Spelling Checker (2003) writing cart to db (1998) LOOP and IF statements (1997) customizing the color of user's pages (1997) bug in listwords? (1998) Protect vs Authenicate (1997) [WebDNA] Installing with MAMP (2015) More Applescript (1997) What is WebDNA (1997) Erotic Sites (1997) can WC render sites out? (1997) [WebDNA] orderfile - encrypt test request (2011) webcat- multiple selection in input field (1997) emailer w/F2 (1997)