[solved in 14c84904fe] Save HTML tags in plugin storage

Development-related discussion, including bundled plugins
feader
Bear Rating Master
Bear Rating Master
Posts: 160
Joined: 26 Dec 2012, 20:03

[solved in 14c84904fe] Save HTML tags in plugin storage

Postby feader » 26 May 2013, 18:41

When I call PluginHost::set($this, 'key', $value), and $value contains HTML tags (i.e. <link>), these are stripped out. This also has the strange effect that retrievals with PluginHost::get($this, 'key') aren't possible, that is, an empty string is returned but there clearly is an entry in the db.
Since I want to store regular expressions that operate on feed data, this is a bit unfortunate. Adding a 'false' to this line in classes/pluginhost.php

Code: Select all

$content = $this->dbh->escape_string(serialize($this->storage[$plugin]), false);

in the save_data function fixes this; I'm don't know if that is a good idea, so should I/the user just "escape" the tags with [<]tag[>]?
Last edited by feader on 27 May 2013, 15:42, edited 1 time in total.

User avatar
fox
^ me reading your posts ^
Posts: 6318
Joined: 27 Aug 2005, 22:53
Location: Saint-Petersburg, Russia
Contact:

Re: Save HTML tags in plugin storage

Postby fox » 27 May 2013, 14:03

I think this was reported before, but I completely forgot about it. Should be fixed in trunk, I don't see why plugins should be prevented from storing html stuff in the database.

feader
Bear Rating Master
Bear Rating Master
Posts: 160
Joined: 26 Dec 2012, 20:03

Re: [solved in 14c84904fe] Save HTML tags in plugin storage

Postby feader » 28 May 2013, 02:57

Works now. I noticed another problem: I have a text field a la af_feedmod in which the user enters data. When a ampersand is entered and stored as &amp;, everything works fine, but on retrieval, it gets converted into a & in the text field. So when the user doesn't recognize this and saves it again, the &amp; is replaced by the sole &, which can have unfortunate consequences (feed gets mangled and is not parsable).

Edit: Here (in the NY Times entry) is an example where &amp; is needed, and & produces an invalid feed.

User avatar
fox
^ me reading your posts ^
Posts: 6318
Joined: 27 Aug 2005, 22:53
Location: Saint-Petersburg, Russia
Contact:

Re: [solved in 14c84904fe] Save HTML tags in plugin storage

Postby fox » 28 May 2013, 08:49

You probably have to htmlspecialchars() it before setting textbox value or something, unless it's stored incorrectly in the database.

feader
Bear Rating Master
Bear Rating Master
Posts: 160
Joined: 26 Dec 2012, 20:03

Re: [solved in 14c84904fe] Save HTML tags in plugin storage

Postby feader » 28 May 2013, 16:49

fox wrote:You probably have to htmlspecialchars() it before setting textbox value or something, unless it's stored incorrectly in the database.

That did the trick, the database was always fine. But it makes me wonder why it worked with the characters <, >, ", ' in it, but chocked only on the &. I should take a good look at textarea stuff, I guess.


Return to “Development”

Who is online

Users browsing this forum: No registered users and 2 guests