[Pushed] The 'double quotes in font lists' browser-independent SCEditor bug
#1
As opposed to my previous two recent SCEditor bug reports, the 'redundant tags on paste of unformatted text' browser-dependent SCEditor bug and the 'reduced size on paste of unformatted text' browser-dependent SCEditor bug, this bug report references solely Hovatek's thread MyCode parse error ( [font="droid sans", sans-serif] ). Along with those two prior bug reports, this one is heavily based on my post #9 in Hovatek's thread, from the first horizontal line onwards.

Specific to this bug report (and note that as opposed to the previous two bugs which were browser-dependent, this bug is browser-independent):

The 'double quotes in font lists' browser-independent SCEditor bug

Description: Sometimes, in scenarios the criteria of which I haven't yet rigorously identified, when pasting text into the WYSIWYG editor, its specified font is actually a comma-separated list of two or more fonts, and at least one of the fonts in that comma-separated list is enclosed in double quotes. When the post is posted, the associated MyBB font tag(s) is/are not rendered by MyBB's PHP parser, because that parser doesn't support double-quotes within the comma-separated list of fonts of a MyCode font tag.

How to reproduce: In any browser, bring up a new editor window through a page such as a New Reply page. Select Source mode. Paste the following MyCode into the editor, after first replacing the curly braces with square braces (since I am posting this on a MyBB forum, I can't paste valid MyCode tags as they would then be rendered - or not, as per this bug!):

{font=Test, "Test two"}Blah{/font}

Switch out of Source mode and then back into it. Confirm that the code has not changed. Then submit or preview the post. Notice that in the rendered post, the raw font tag shows up unrendered.

Impact: Moderate-severe. There can at times be so many of these unrendered font tags that the post once posted is effectively unreadable.

A working solution: Simply replace in the file jscript/bbcodes_sceditor.js the following code from within the "format" method relating to the "font" bbcode:

				return '[font=' + this.stripQuotes(font) + ']' + content + '[/font]';

with this:

				if (font[0] == '"' && font[font.length-1] == '"' && (font.match(/"/g) || []).length == 2) {
					font = font.substr(1, font.length-2);
				}
				font = font.replace(/"/g, "'");
				return '[font=' + font + ']' + content + '[/font]';

Now, when text is pasted into the editor in WYSIWYG mode, or when switching into Source mode, double quotes within lists of fonts are replaced with single quotes. Problem solved.

Additionally, it might be worth integrating into core code the code from my basic plugin attached to post #4 in Hovatek's thread. That code handles posts that have already been posted with double-quotes in their font tags, such that even with the above fix, those font tags display unrendered in the absence of the plugin's code.
Reply
#2
Thank you, I just applied to my board.
[MyBB 1.8 Czech translation] [MyBB 1.8 plugins]: Prune old PMs + optimize DB plugin --- Thank you/like system
Reply
#3
(2020-10-07, 06:16 PM)Eldenroot Wrote: Thank you, I just applied to my board.

No worries. Just a heads-up: I made a minor error in the replacement php - the second parameter of the call to font.substr() should be font.length-2 rather than -1. It seems that substr interprets a negative length as zero, rather than characters from the end as I'd thought. Have edited my post to correct that. Please correct on your forum.
Reply
#4
Corrected, thank you!
[MyBB 1.8 Czech translation] [MyBB 1.8 plugins]: Prune old PMs + optimize DB plugin --- Thank you/like system
Reply
#5
Hmm, I have different thoughts on it.

It's a browser dependent issue when it comes to copy and paste on different web browsers on different operating systems.

OP's code does fix the issue but the fix is for another different perspective the root cause may not be in. IMO we're not going to make MyBB compliant to anything inputted by users, whereas we should look into the root cause of different browser behaviors. Anyway, if we can't make the editor behave consistently across browsers, we apply OP's fix.

Edited:
Will It be more convenient to just fix this line? https://github.com/mybb/mybb/blob/mybb_1...r.php#L371
Could be wrong but worth a try.
Reply
#6
(2020-10-13, 09:27 AM)noyle Wrote: It's a browser dependent issue when it comes to copy and paste on different web browsers on different operating systems.

Are you saying that some browsers on some OSes use double-quotes for some fonts in a list of fonts, whereas others don't? Honestly, I haven't investigated to that extent, so you could be right.

I categorised the bug as browser-independent because once the double-quotes get into the fonts in a list of fonts - however they get there, whether through copy-paste or user error in Source mode - the editor does nothing to eliminate them (it does not, e.g., convert them into single-quotes), including when switching out of and back into Source mode, and this lack of correction by the editor is independent of which browser is being used.

(2020-10-13, 09:27 AM)noyle Wrote: OP's code does fix the issue but the fix is for another different perspective the root cause may not be in. IMO we're not going to make MyBB compliant to anything inputted by users, whereas we should look into the root cause of different browser behaviors.

Sure, if we can stop browsers in conjunction with SCEditor from generating lists of fonts with double-quotes in them, then my fix above is unnecessary. I don't know how we'd do that though.

(2020-10-13, 09:27 AM)noyle Wrote: Will It be more convenient to just fix this line? https://github.com/mybb/mybb/blob/mybb_1...r.php#L371

That was my initial thought, but I couldn't think of a way to use that single line (in conjunction with its replacement code one line down) to eliminate all double-quotes within what is now the second match (maybe, though, we could convert it to use a callback). I settled instead for pre-parsing font tags to achieve that outcome - which is what my little fixunrenderedfonttags.php plugin from post #4 in Hovatek's thread does.
Reply
#7
Hi,

Thank you for your report. We have pushed this issue to our Github repository for further analysis where you can track our commits and progress with fixing this bug. Discussions regarding this bug may also take place there too.

Follow this link to visit the issue on Github: https://github.com/mybb/mybb/issues/4182

Thanks for contributing to MyBB!

Regards,
The MyBB Group
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)