Skip to main content
Topic: BBC tag with spaces (Read 3919 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

BBC tag with spaces

Alright so i know this is not really a bug as such but its an issue none the less.

If you have a tag such as [img ]http://imgurl.com[/img] (with a space after the tag) it will not parse when going through parse_bbc and will just output as text.

For some reason when i converted my forum over from smf all [img] tags without width/height info in them in my old forum got ported over with a space instead after the tag and thus my forum is full of unparsed images.

Have done a quick fix myself in parse_bbc in subs.php but prefer to not have a bunch of custom edits that makes upgrading a pain in the future ;)

Re: BBC tag with spaces

Reply #1

hmm... it would be more suited for a feature request than a bug report. :P
But that aside... I feel it could be possible to create a "new" image tag with the space at the end and add it through an addon.
I "feel" because by memory I'm not sure if there is any trim around the code.

Basically the two existing img tags with "just" a space in tag:
Code: [Select]
				'tag' => 'img ',
Bugs creator.
Features destroyer.
Template killer.

Re: BBC tag with spaces

Reply #2

Hmm... yeah. That's an issue I guess but not one I'd want to fix. The fix would cause parsing to be slower. As for using two tags, at first I thought that might not work but thinking about it, it might. An easy test and it would be future proof.

Re: BBC tag with spaces

Reply #3

Quote from: emanuele – hmm... it would be more suited for a feature request than a bug report. :P
But that aside... I feel it could be possible to create a "new" image tag with the space at the end and add it through an addon.
I "feel" because by memory I'm not sure if there is any trim around the code.

Basically the two existing img tags with "just" a space in tag:
Code: [Select]
				'tag' => 'img ',

Yeah i did start out by writing wasn't really a bug as such ;) Just couldn't think of a better place to put it at the time. The proposed fix does not work by the way.
My own hackish fix was just to do the following: $message = str_replace('[img ]', '[img]', $message);
Which does work but it's certainly not very elegant.

Quote from: Joshua Dickerson – Hmm... yeah. That's an issue I guess but not one I'd want to fix. The fix would cause parsing to be slower. As for using two tags, at first I thought that might not work but thinking about it, it might. An easy test and it would be future proof.

The parser has already hundreds of string replacing being done, hardly make a difference to add 1 more, but yes generally agree.


Another slightly related thing i found with data coming from another forum, if you have a tag with
Code: [Select]
[font=whatever] .. [/font]
and that font is not supported, the
Code: [Select]
[font]
entry is ignored in the message but the
Code: [Select]
[/font]
shows up as raw text in the message.

Re: BBC tag with spaces

Reply #4

If it's not an enormous forum, what about a query scanning all posts, looking for [img ] and replace it with the regular tag? Wouldn't that be possible?
~ SimplePortal Support Team ~

Re: BBC tag with spaces

Reply #5

Quote from: Acido – My own hackish fix was just to do the following: $message = str_replace('[img ]', '[img]', $message);
Which does work but it's certainly not very elegant.
The important part is that it works, and is actually was less overhead than my proposal. ;)
If you want it can be converted to an addon so that you don't even need code edits (using the integrate_pre_parsebbc hook).
Bugs creator.
Features destroyer.
Template killer.

Re: BBC tag with spaces

Reply #6

Quote from: Acido – Another slightly related thing i found with data coming from another forum, if you have a tag with
Code: [Select]
[font=whatever] .. [/font]
and that font is not supported, the
Code: [Select]
[font]
entry is ignored in the message but the
Code: [Select]
[/font]
shows up as raw text in the message.
If the tag is a string, it should be parsed in any case (string in the sense anything that matches the pattern [A-Za-z0-9_,\-\s]+?\]), if for example the name is surrounded by double quotes, instead, it is not.
Bugs creator.
Features destroyer.
Template killer.

Re: BBC tag with spaces

Reply #7

I wasn't thinking that as a solution since that just fixes your tiny problem. I was thinking of allowing the space there for any tag.

Solution to your problem is a simple query

Re: BBC tag with spaces

Reply #8

Yeah i did consider just converting the messages in database, but is little over 1.2 million messages so would have to do it in the shell as to not timeout php.

Quote from: emanuele –
Quote from: Acido – Another slightly related thing i found with data coming from another forum, if you have a tag with
Code: [Select]
[font=whatever] .. [/font]
and that font is not supported, the
Code: [Select]
[font]
entry is ignored in the message but the
Code: [Select]
[/font]
shows up as raw text in the message.
If the tag is a string, it should be parsed in any case (string in the sense anything that matches the pattern [A-Za-z0-9_,\-\s]+?\]), if for example the name is surrounded by double quotes, instead, it is not.

It is parsed as i said the actual font line does not appear but the /font is not parsed and will appear as raw text when the font requested is invalid, or so it seems. I can do some more testing on it.

I also have some other unparsed tags but those are just tags not supported in ElkArte like [float=left/right] but if i have to do the query anyway I'll fix those at the same time.
Last Edit: May 30, 2016, 08:01:02 pm by Acido

Re: BBC tag with spaces

Reply #9

What are you using for searching? Use that to find the rows to change. That should make your conversion script a lot faster since you won't have to search every row. Run it via command line php convert.php and do the query in batches of 1000 or so.

Since it's just a simple update query and it doesn't need to go back to PHP, you could look in to use Percona Tools.

Re: BBC tag with spaces

Reply #10

Quote from: Acido – It is parsed as i said the actual font line does not appear but the /font is not parsed and will appear as raw text when the font requested is invalid, or so it seems. I can do some more testing on it.
Hmm... it could be another artefact of the conversion:
http://www.elkarte.it/community/index.php?topic=7.0
The odd thing is that at "parse_bbc" level, the only test performed is the regular expression ruling out strings containing special characters, so elk doesn't know what is a "valid" font or not (and nowhere there is a check for "valid" fonts, on the basis that add new fonts would be troublesome for a very little benefit).
This one looks like a misplaced tag in fact. I would check these messages to see if there is something that should not be there (for example another "block-level" (list, code, quote, table, center, left, right, maybe others) tag between the opening and closing font)

Quote from: Acido – I also have some other unparsed tags but those are just tags not supported in ElkArte like [float=left/right] but if i have to do the query anyway I'll fix those at the same time.
If you need them, add a float is not particularly difficult. ;)
Bugs creator.
Features destroyer.
Template killer.

Re: BBC tag with spaces

Reply #11

Yes you are correct, ignore the font thing, i found the issue. The messages was doing something like this:
Code: [Select]
[size=7][font=fontname]a bunch of text[/size][/font]

Wrong order of termination of the tags.

Re: BBC tag with spaces

Reply #12

Sounds like a bunch of changes you could make with an update query. If you're having problems writing it out, post and someone will probably help.

Either way, maybe you can post your queries/solution so others can benefit.

Re: BBC tag with spaces

Reply #13

Quote from: Joshua Dickerson – Sounds like a bunch of changes you could make with an update query. If you're having problems writing it out, post and someone will probably help.

Either way, maybe you can post your queries/solution so others can benefit.

Don't know if my case is anything special, but I just did the following simple query to correct the img issue first of all:
Code: [Select]
UPDATE
    {$prefix}messages
SET
    Body = Replace(Body, '[img ]', '[img]')

Wasn't actually too bad: 32566 rows affected. ( Query took 20.6203 sec )
Last Edit: May 31, 2016, 02:30:52 pm by Acido

Re: BBC tag with spaces

Reply #14

You can use a simple regular expression for the [/size][/font] issue