Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

A list is only as strong as its weakest link. -- Don Knuth


devel / comp.lang.tcl / string map in wapp-subst

SubjectAuthor
* string map in wapp-substLuis Mendes
+* Re: string map in wapp-substLuis Mendes
|`* Re: string map in wapp-substRich
| `* Re: string map in wapp-substLuis Mendes
|  `- Re: string map in wapp-substRich
`* Re: string map in wapp-substRich
 `- Re: string map in wapp-substLuis Mendes

1
string map in wapp-subst

<66338589$0$719$14726298@news.sunsite.dk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=23930&group=comp.lang.tcl#23930

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.nntp4.net!usenet.goja.nl.eu.org!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail
From: luisXXXlupeXXX@gmail.com (Luis Mendes)
Subject: string map in wapp-subst
Newsgroups: comp.lang.tcl
MIME-Version: 1.0
User-Agent: Pan/0.154 (Izium; 517acf4)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Date: 02 May 2024 12:22:33 GMT
Lines: 43
Message-ID: <66338589$0$719$14726298@news.sunsite.dk>
Organization: SunSITE.dk - Supporting Open source
NNTP-Posting-Host: 8f3602c6.news.sunsite.dk
X-Trace: 1714652553 news.sunsite.dk 719 luislupe@gmail.com/176.79.85.73:50804
X-Complaints-To: staff@sunsite.dk
 by: Luis Mendes - Thu, 2 May 2024 12:22 UTC

Hi,

I'm using Wapp[1] to build a small web application.
To show some results previously saved in s SQLite database, there's this
code (simplified):
foreach descr $test {
wapp-trim "
<td>%html($descr)</td>
"
}

Some of descr have square brackets in their strings, like:
{"changed": false, "msg": "This has value ([])"}

As I'm using Tcl 8.6.13 the warning at https://wapp.tcl.tk/home/doc/trunk/
docs/commands.md applies:

Caution #1: When using Tcl 8.6 or earlier, command substitution, but not
variable substitution, occurs outside of the quoted regions. This problem
is fixed using the new "-command" option to the regsub command in Tcl 8.7.
Nevertheless, it is suggested that you avoid using the "[" character
outside of the %-quotes. Use "&#91;" instead.

My attempt to string map [ to the corresponding html code have failed,
like:

string map " {[} {&#91;} " $descr
string map { "[" "&#91;" } $descr

Also tried to escape the [, but to no success.

How can it be done?

Thanks,

Luís

[1] https://wapp.tcl.tk/

Re: string map in wapp-subst

<66339481$0$719$14726298@news.sunsite.dk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=23931&group=comp.lang.tcl#23931

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail
From: luisXXXlupeXXX@gmail.com (Luis Mendes)
Subject: Re: string map in wapp-subst
Newsgroups: comp.lang.tcl
References: <66338589$0$719$14726298@news.sunsite.dk>
MIME-Version: 1.0
User-Agent: Pan/0.154 (Izium; 517acf4)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Date: 02 May 2024 13:26:25 GMT
Lines: 50
Message-ID: <66339481$0$719$14726298@news.sunsite.dk>
Organization: SunSITE.dk - Supporting Open source
NNTP-Posting-Host: 7f72b0d6.news.sunsite.dk
X-Trace: 1714656385 news.sunsite.dk 719 luislupe@gmail.com/176.79.85.73:50804
X-Complaints-To: staff@sunsite.dk
 by: Luis Mendes - Thu, 2 May 2024 13:26 UTC

On 02 May 2024 12:22:33 GMT, Luis Mendes wrote:

> Hi,
>
> I'm using Wapp[1] to build a small web application.
> To show some results previously saved in s SQLite database, there's this
> code (simplified):
> foreach descr $test {
> wapp-trim "
> <td>%html($descr)</td>
> "
> }
>
> Some of descr have square brackets in their strings, like:
> {"changed": false, "msg": "This has value ([])"}
>
> As I'm using Tcl 8.6.13 the warning at
> https://wapp.tcl.tk/home/doc/trunk/" rel="nofollow" target="_blank">https://wapp.tcl.tk/home/doc/trunk/
> docs/commands.md applies:
>
> Caution #1: When using Tcl 8.6 or earlier, command substitution, but not
> variable substitution, occurs outside of the quoted regions. This
> problem is fixed using the new "-command" option to the regsub command
> in Tcl 8.7.
> Nevertheless, it is suggested that you avoid using the "[" character
> outside of the %-quotes. Use "&#91;" instead.
> [1] https://wapp.tcl.tk/

Upon further investigation, it seems that the problem doesn't happen
because of the [, but because of quotes.
I could already do the string map mentioned in the previous post.

If I try `set descr "\"changed\": false"
it breaks wapp.
The error returned is:
ERROR: extra characters after close-quote.

Although at that [1] web page it's said:
"""
wapp-subst TEXT
This command appends text to the end of reply to an HTTP request. The TEXT
argument should be enclosed in {...} to prevent accidental substitutions.
The "wapp-subst" command itself will do all necessary backslash
substitutions. Command and variable substitutions occur within
"%html(...)", "%url(...)", "%qp(...)", "%string(...)", and "%unsafe(...)".
The substitutions are escaped (except in the case of "%unsafe(...)") so
that the result is safe for inclusion within the body of an HTML document,
a URL, a query parameter, or a javascript or JSON string literal,
respectively.
"""

Re: string map in wapp-subst

<v1068c$3so2d$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=23932&group=comp.lang.tcl#23932

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: string map in wapp-subst
Date: Thu, 2 May 2024 13:59:40 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <v1068c$3so2d$1@dont-email.me>
References: <66338589$0$719$14726298@news.sunsite.dk>
Injection-Date: Thu, 02 May 2024 15:59:40 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="1141aa5a52dd0ac99e8a5d1c958db114";
logging-data="4087885"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/CExhlhcF4wVgGniCGnHWY"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:oWbqgygpaCS+zZEj0Ur3aIsd1NE=
 by: Rich - Thu, 2 May 2024 13:59 UTC

Luis Mendes <luisXXXlupeXXX@gmail.com> wrote:
> My attempt to string map [ to the corresponding html code have failed,
> like:
>
> string map " {[} {&#91;} " $descr
> string map { "[" "&#91;" } $descr
>
> Also tried to escape the [, but to no success.
>
> How can it be done?

Although your followup implies you no longer need the answer to this,
the way "to do it" is to feed a proper list to string map:

string map [list \[ "&#91;"] $descr

It is usually more difficult to try to create lists using "" or {} than
to just let the [list] command do so. In either of the first cases,
you have to have a very good internal understanding of what to quote
(and not to quote) to make the list correct. Using [list], it will
handle those details for you automatically.

Re: string map in wapp-subst

<v106b8$3so2d$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=23933&group=comp.lang.tcl#23933

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: string map in wapp-subst
Date: Thu, 2 May 2024 14:01:12 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <v106b8$3so2d$2@dont-email.me>
References: <66338589$0$719$14726298@news.sunsite.dk> <66339481$0$719$14726298@news.sunsite.dk>
Injection-Date: Thu, 02 May 2024 16:01:13 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="1141aa5a52dd0ac99e8a5d1c958db114";
logging-data="4087885"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18qwM5p4lirCNR5iju6qpM8"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:QV9cJtv/cMJrWP2VQRrhd7pVjbY=
 by: Rich - Thu, 2 May 2024 14:01 UTC

Luis Mendes <luisXXXlupeXXX@gmail.com> wrote:
> On 02 May 2024 12:22:33 GMT, Luis Mendes wrote:
> Upon further investigation, it seems that the problem doesn't happen
> because of the [, but because of quotes.
> I could already do the string map mentioned in the previous post.
>
> If I try `set descr "\"changed\": false"
> it breaks wapp.
> The error returned is:
> ERROR: extra characters after close-quote.

What if you escape actual quotes into the html &quot; escape?

string map [list \" "&quot;"] $your_variable

Re: string map in wapp-subst

<66339fee$0$719$14726298@news.sunsite.dk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=23934&group=comp.lang.tcl#23934

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!rocksolid2!news.neodome.net!weretis.net!feeder8.news.weretis.net!usenet.goja.nl.eu.org!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail
From: luisXXXlupeXXX@gmail.com (Luis Mendes)
Subject: Re: string map in wapp-subst
Newsgroups: comp.lang.tcl
References: <66338589$0$719$14726298@news.sunsite.dk>
<v1068c$3so2d$1@dont-email.me>
MIME-Version: 1.0
User-Agent: Pan/0.154 (Izium; 517acf4)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Date: 02 May 2024 14:15:10 GMT
Lines: 25
Message-ID: <66339fee$0$719$14726298@news.sunsite.dk>
Organization: SunSITE.dk - Supporting Open source
NNTP-Posting-Host: fe5dfdc4.news.sunsite.dk
X-Trace: 1714659310 news.sunsite.dk 719 luislupe@gmail.com/176.79.85.73:50804
X-Complaints-To: staff@sunsite.dk
 by: Luis Mendes - Thu, 2 May 2024 14:15 UTC

On Thu, 2 May 2024 13:59:40 -0000 (UTC), Rich wrote:

> Luis Mendes <luisXXXlupeXXX@gmail.com> wrote:
>> My attempt to string map [ to the corresponding html code have failed,
>> like:
>>
>> string map " {[} {&#91;} " $descr string map { "[" "&#91;" } $descr
>>
>> Also tried to escape the [, but to no success.
>>
>> How can it be done?
>
> Although your followup implies you no longer need the answer to this,
> the way "to do it" is to feed a proper list to string map:
>
> string map [list \[ "&#91;"] $descr
>
> It is usually more difficult to try to create lists using "" or {} than
> to just let the [list] command do so. In either of the first cases, you
> have to have a very good internal understanding of what to quote (and
> not to quote) to make the list correct. Using [list], it will handle
> those details for you automatically.

Great tip Rich!
Thank you very much.

Re: string map in wapp-subst

<6633a199$0$719$14726298@news.sunsite.dk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=23935&group=comp.lang.tcl#23935

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.nntp4.net!usenet.goja.nl.eu.org!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail
From: luisXXXlupeXXX@gmail.com (Luis Mendes)
Subject: Re: string map in wapp-subst
Newsgroups: comp.lang.tcl
References: <66338589$0$719$14726298@news.sunsite.dk>
<66339481$0$719$14726298@news.sunsite.dk> <v106b8$3so2d$2@dont-email.me>
MIME-Version: 1.0
User-Agent: Pan/0.154 (Izium; 517acf4)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Date: 02 May 2024 14:22:17 GMT
Lines: 22
Message-ID: <6633a199$0$719$14726298@news.sunsite.dk>
Organization: SunSITE.dk - Supporting Open source
NNTP-Posting-Host: fe5dfdc4.news.sunsite.dk
X-Trace: 1714659737 news.sunsite.dk 719 luislupe@gmail.com/176.79.85.73:50804
X-Complaints-To: staff@sunsite.dk
 by: Luis Mendes - Thu, 2 May 2024 14:22 UTC

On Thu, 2 May 2024 14:01:12 -0000 (UTC), Rich wrote:

> Luis Mendes <luisXXXlupeXXX@gmail.com> wrote:
>> On 02 May 2024 12:22:33 GMT, Luis Mendes wrote:
>> Upon further investigation, it seems that the problem doesn't happen
>> because of the [, but because of quotes.
>> I could already do the string map mentioned in the previous post.
>>
>> If I try `set descr "\"changed\": false"
>> it breaks wapp.
>> The error returned is:
>> ERROR: extra characters after close-quote.
>
> What if you escape actual quotes into the html &quot; escape?
>
> string map [list \" "&quot;"] $your_variable
Wapp doens't break, but then the &quot; is not interpreted back to a "
when rendered in html.

I've substituted " by ' and it works, although not as accurate.
Thank you.

Re: string map in wapp-subst

<v10962$3tg6d$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=23936&group=comp.lang.tcl#23936

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.samoylyk.net!newsfeed.xs3.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: string map in wapp-subst
Date: Thu, 2 May 2024 14:49:38 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <v10962$3tg6d$1@dont-email.me>
References: <66338589$0$719$14726298@news.sunsite.dk> <66339481$0$719$14726298@news.sunsite.dk> <v106b8$3so2d$2@dont-email.me> <6633a199$0$719$14726298@news.sunsite.dk>
Injection-Date: Thu, 02 May 2024 16:49:38 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="1141aa5a52dd0ac99e8a5d1c958db114";
logging-data="4112589"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/bytK28v/j+CyTKXC1PV/c"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:nqfVz+OA2sTDctgmo2unigOYKE0=
 by: Rich - Thu, 2 May 2024 14:49 UTC

Luis Mendes <luisXXXlupeXXX@gmail.com> wrote:
> On Thu, 2 May 2024 14:01:12 -0000 (UTC), Rich wrote:
>
>> Luis Mendes <luisXXXlupeXXX@gmail.com> wrote:
>>> On 02 May 2024 12:22:33 GMT, Luis Mendes wrote:
>>> Upon further investigation, it seems that the problem doesn't happen
>>> because of the [, but because of quotes.
>>> I could already do the string map mentioned in the previous post.
>>>
>>> If I try `set descr "\"changed\": false"
>>> it breaks wapp.
>>> The error returned is:
>>> ERROR: extra characters after close-quote.
>>
>> What if you escape actual quotes into the html &quot; escape?
>>
>> string map [list \" "&quot;"] $your_variable
> Wapp doens't break, but then the &quot; is not interpreted back to a "
> when rendered in html.
>
> I've substituted " by ' and it works, although not as accurate.
> Thank you.

Then you might try escaping the quotes:

string map [list \" \\\"] $your_variable

And see if Wapp handles \" within the string properly.


devel / comp.lang.tcl / string map in wapp-subst

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor