Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-09-14 11:41:17

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,806
GitHub

Apostrophes/single quotes in article titles

Hi.
I’m using this in an article form to output some footer links in a ul:

<li><txp:permlink title='<txp:title /> was posted <txp:posted format="since" />'><txp:title /></txp:permlink></li>

…which outputs something like this on hover (article title in this case is I like hot toast):

I like hot toast was posted 4 hours ago

This is great, and exactly what I was expecting. However, if title contains an apostrophe, the hover now looks like this (article title in this case is I ate Stef's hot toast):

I ate Stef’s hot toast was posted 3 hours ago

Which is not so great. Is there a way to change the ' to an apostrophe? I was wondering if rah_replace would do it, but it seems a little overkill for the task.

Thank you in advance.

Last edited by gaekwad (2012-09-15 11:17:25)

Offline

#2 2012-09-14 13:31:50

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

Re: Apostrophes/single quotes in article titles

If rah_replace is already installed on the site, it’s fine to use it here. Otherwise, I can not find anything better than title='<txp:php>echo str_replace("&#39 ;", "''", title(array()));</txp:php> was posted <txp:posted format="since" />'

Edit: delete the space between &#39 and ;, textile is stronger than me.

Last edited by etc (2012-09-14 13:36:08)

Offline

#3 2012-09-14 13:40:25

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,806
GitHub

Re: Apostrophes/single quotes in article titles

Thank you, Oleg — rah_replace is already installed, so I’ll go ahead and use that.

Offline

#4 2012-09-14 17:13:47

makss
Plugin Author
From: Ukraine
Registered: 2008-10-21
Posts: 355

Re: Apostrophes/single quotes in article titles

or use double quotes

<a href="<txp:permlink />" title="<txp:title />" ><txp:title /></a>

but then the title should be no double quotes.. :)

Last edited by makss (2012-09-14 17:14:28)


aks_cron : Cron inside Textpattern | aks_article : extended article_custom tag
aks_cache : cache for TxP | aks_dragdrop : Drag&Drop categories (article, link, image, file)

Offline

#5 2012-09-15 10:47:15

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

Re: Apostrophes/single quotes in article titles

makss wrote:

or use double quotes

Amazing, nice one!

Offline

#6 2012-09-15 10:51:31

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,806
GitHub

Re: Apostrophes/single quotes in article titles

makss wrote:

or use double quotes

Hi makss.
Thank you for your reply. The problem I have with double quotes is parsing <txp:posted format="since" /> as it contains double quotes and is important to the output. I can’t test it right now, but would this work:

<li><txp:permlink title=”<txp:title /> was posted <txp:posted format=‘since’ />”><txp:title /></txp:permlink></li>

Last edited by gaekwad (2012-09-15 10:51:50)

Offline

#7 2012-09-15 11:12:37

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

Re: Apostrophes/single quotes in article titles

gaekwad wrote:

I can’t test it right now, but would this work:

<li><txp:permlink title="<txp:title /> was posted <txp:posted format='since' />"><txp:title /></txp:permlink></li>

Yes, it works, and that’s amazing. Not this one, but

<a href="<txp:permlink />" title="<txp:title /> was posted <txp:posted format='since' />" ><txp:title /></a>

will.

Last edited by etc (2012-09-15 11:16:18)

Offline

#8 2012-09-15 11:13:58

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,806
GitHub

Re: Apostrophes/single quotes in article titles

etc wrote:

Yes, it works, and that’s amazing. Txp parser does marvels.

Thank you again, Oleg – I am very grateful for your assistance.

Offline

#9 2012-09-15 11:16:50

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

Re: Apostrophes/single quotes in article titles

Sorry, I was too fast. Actually, this one works too:

<txp:permlink title="<txp:title /> was posted <txp:posted format='since' />"><txp:title /></txp:permlink>

Txp parser does marvels.

Last edited by etc (2012-09-15 11:43:38)

Offline

#10 2012-09-15 16:59:36

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: Apostrophes/single quotes in article titles

<txp:permlink title="<txp:title /> was posted <txp:posted format='since' />"><txp:title /></txp:permlink>

That shouldn’t be working, AFAIK.
Parsing tags in tags require simple quotes (at least, for a one-level depth).
The above line should be:

<txp:permlink title='<txp:title /> was posted <txp:posted format="since" />'><txp:title /></txp:permlink>

La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#11 2012-09-15 17:09:59

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,806
GitHub

Re: Apostrophes/single quotes in article titles

maniqui wrote:

<txp:permlink title='<txp:title /> was posted <txp:posted format="since" />'><txp:title /></txp:permlink>

Thanks, Julián, that’s good to know — exactly what I was using in my opening post.

Offline

#12 2012-09-15 19:16:41

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

Re: Apostrophes/single quotes in article titles

maniqui wrote:

<txp:permlink title="<txp:title /> was posted <txp:posted format='since' />"><txp:title /></txp:permlink>

That shouldn’t be working, AFAIK.

That’s what I thought too, but I’m testing and retesting – it works. Could somebody confirm?

Offline

#13 2012-09-15 20:33:56

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Apostrophes/single quotes in article titles

etc wrote:

That’s what I thought too, but I’m testing and retesting – it works. Could somebody confirm?

As Julián says, it shouldn’t work. If it works, you have some type of extra parser call, an additional parser and/or unsanitizer somewhere running, most likely doing of a plugin.

When double quotes are used, the contents are treated and returned as it is. Nothing is parsed. Permlink tag also returns contents sanitized, so there is no change them being parsed by anything after that point. Normally you would need to use single quotes when an attribute value contains tags.

In other words, if the double quoted values are parsed even when sanitized, I would advice looking into what causes that ASAP if you use same plugins/code on live installations. Because if that is truly happening, you may have some pretty serious security issue laying there. If that same happens to user-defined content (e.g. search query value), well, that’s no good.

Last edited by Gocom (2012-09-15 20:44:14)

Offline

#14 2012-09-16 09:34:59

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

Re: Apostrophes/single quotes in article titles

Gocom wrote:

As Julián says, it shouldn’t work. If it works, you have some type of extra parser call, an additional parser and/or unsanitizer somewhere running, most likely doing of a plugin.

Guys, I agree it shouldn’t work, and it doesn’t on another localhost site, but it works on at least one of them (4.4.1 on wamp). Globally disabled plugins, php, installed vanilla page/article forms, even emptied cache – it’s still there. Even funnier: <txp:permlink title='<txp:title />'><txp:title /></txp:permlink> gives me true quotes in tooltip, not &#39 ; or &#34 ;.

I have changed one line in publish.php, but it has nothing to do with parsing. That’s weird.

Edit: and it does not work on the remote from which the site has been imported, though they have diverged since.

Last edited by etc (2012-09-16 09:39:55)

Offline

#15 2012-09-16 10:34:59

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

Re: Apostrophes/single quotes in article titles

Looks like this weirdness happens only with the title attribute of <txp:permlink />, and only in 4.4.1. I have tested other tags/attributes – everything works as expected there.

Offline

Board footer

Powered by FluxBB