Jermolene / TiddlyWiki5

A self-contained JavaScript wiki for the browser, Node.js, AWS Lambda etc.
https://tiddlywiki.com/
Other
7.79k stars 1.16k forks source link

Make sure split(regex) returns an array of strings #8222

Closed pmario closed 3 weeks ago

pmario commented 1 month ago

This PR makes sure split(regex) used by the splitregexp operator returns an array of strings. It fixes: #8216 and #8213

Code to test with

\define re() (color)|(colour)ed
\define str() Something coloured
{{{ [<str>splitregexp<re>join[, ]] }}}

---

{{{ [<str>splitregexp<re>] }}}

image

vercel[bot] commented 1 month ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
tiddlywiki5 ✅ Ready (Inspect) Visit Preview Jun 6, 2024 11:39am
pmario commented 3 weeks ago

@Jermolene -- Please confirm that the following code should create the output as shown in the screenshtot.

\define re() (color)|(colour)ed
\define str() Something coloured
{{{ [<str>splitregexp<re>join[, ]] }}}

---

{{{ [<str>splitregexp<re>] }}}

image

Jermolene commented 3 weeks ago

Hi @pmario the issue here is that the JS split operator is essentially useless when used with a regex that includes capture groups.

So, I think the best we can do is coerce undefined to an empty string, and add a warning to the docs for the split operator explaining why it should not be used with capture groups.

pmario commented 3 weeks ago

So, I think the best we can do is coerce undefined to an empty string, and add a warning to the docs for the split operator explaining why it should not be used with capture groups.

OK - I'll some info to the docs too.

pmario commented 3 weeks ago

@Jermolene -- This should work as requested now + a bit more docs

Jermolene commented 3 weeks ago

Thank you @pmario