Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2024-01-06 03:07:18

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,012
Website GitHub Mastodon Twitter

[SOLVED] trim bug in shortcode?

I have the following shortcode for external links

<a<txp:if_yield name="nf"> rel="nofollow noopener"
<txp:else /> 
rel="external noopener"</txp:if_yield>
<txp:if_yield name="lang"> lang="<txp:yield name="lang" />"</txp:if_yield> 
href="<txp:yield name="url" />"<txp:if_yield name="email"> style="color:#ba0000;text-decoration:none;"</txp:if_yield>
<txp:if_yield name="class"> class="<txp:yield name="class" />"</txp:if_yield>>
<txp:if_yield name="txt"><txp:yield name="txt" /><txp:else />
<txp:yield name="url" trim="https?://www.?" /></txp:if_yield></a>

It all works just fine except, there appears to be a strange bug with the trim function.

When I use the shortcode like <txp::ext url="https://domain.tld" /> it all works fine and parses as it should: <a rel="external noopener" href="https://domain.tld">domain.tld</a>

If I use it the same way but the site domain starts with a t, the following happens

shortcode: <txp::ext url="https://tomain.tld" />

Parses to <a rel="external noopener" href="https://tomain.tld">omain.tld</a>, trimming the first t.

Any ideas why this is happening?


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#2 2024-01-06 10:56:29

etc
Developer
Registered: 2010-11-11
Posts: 5,054
Website GitHub

Re: [SOLVED] trim bug in shortcode?

It’s not really a bug, I’m surprised it works at all. To trigger regex mode, trim must be a valid delimited regex pattern, like #^https?://(www\.)?#i. Otherwise, it will just progressively strip all provided characters (including t) at url extremities.

Offline

#3 2024-01-06 16:14:48

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,012
Website GitHub Mastodon Twitter

Re: [SOLVED] trim bug in shortcode?

etc wrote #336297:

It’s not really a bug, I’m surprised it works at all. To trigger regex mode, trim must be a valid delimited regex pattern, like #^https?://(www\.)?#i. Otherwise, it will just progressively strip all provided characters (including t) at url extremities.

#^https?://(www\.)?#i did indeed fix it! I had the trim function for some time but I had no urls that started or finished the a t so I never noticed my error.

Thanks so much Oleg!


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

Board footer

Powered by FluxBB