Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
[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
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
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 (includingt
) aturl
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
Pages: 1