Skip to main content
Topic: The alt param for the img tag (Read 2442 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

The alt param for the img tag

While adding some more tests for the BBC parser, I found a little tricky situation:
Code: [Select]
[img alt=some text height=100 width=150]http://i.imgur.com/eO1zpA7.jpg%20http://i384.photobucket.com/albums/oo283/piter91/spoiler_zpsvzbgpxcv.png[/img]
This one is parsed into:
Code: [Select]
<img src="http://i.imgur.com/eO1zpA7.jpg%20http://i384.photobucket.com/albums/oo283/piter91/spoiler_zpsvzbgpxcv.png" alt="some text height=100" style="width:100%;max-width:150px;" class="bbc_img resized" />

The wrong part is the alt attribute:
Code: [Select]
alt="some text height=100"

It's indeed an edge case because 1) the alt parameter doesn't have any validation, as such, anything it has inside is good, 2) for a chance, the first regex that is tested and matches is:
Code: [Select]
~^(\s+alt=(.+?))?(\s+width=(\d+))?(\s+height=(\d+))?\]~i

Sooo, options:
1) whistle innocently and ignore it (possible),
2) make the alt a quoted parameter,
3) find a fix.

At the moment I just found what I think it's a workaround changing the exit condition to:
Code: [Select]
} while ((!$match || count($matches) !== (count($keys) * 2 + 1)) && --$max_iterations && ($keys = pc_next_permutation($keys, $possible['regex_size'])));

in particular, the original:
Code: [Select]
!$match
changed to:
Code: [Select]
(!$match || count($matches) !== (count($keys) * 2 + 1))
[1]
That relies on the fact that if not all matches are found, something may be wrong and keeps trying.
Though, I have the feeling this will break in cases there are less than the maximum number of parameter. But I should test it more in details, also I'm not sure of the impact in case of bbcodes with "too many" parameter.

Opinions?
Side note: I didn't write all the text up to here in one go, though I used ctrl+z here and the undo deleted the entire message! :o
Bugs creator.
Features destroyer.
Template killer.

Re: The alt param for the img tag

Reply #1

And that my friend, is why I always write <img src="url" then style here and then alt as last>.

[1]
Doesn't ctrl y work as re-do? If not, it REALLY should, I think.
~ SimplePortal Support Team ~

Re: The alt param for the img tag

Reply #2

Quoted is the easiest I think

I was thinking that non-quoted parameters shouldn't allow spaces. It doesn't make sense to.