Nao

  • Dadman with a boy
  • Posts: 16,079
BBCode trimming issues?
« on March 21st, 2012, 10:16 AM »
So, I've never been familiar with the 'trim' (trim_wspace in the database) parameter of bbcodes.

The Noisen codebase automatically trims whitespace before and after quotes, because I hate it when people don't insert any whitespace and we end up with quotes touching the rest of the text, so I trimmed everything out and added extra margins to compensate.

Now, with Wedge I didn't add this code because I'm trying to stay away from 'hacks'... After discussing with Pete, it seemed like the obvious answer was to change the trim_wspace value of quote tags from 'none' to 'outside' (meaning, 'trim any whitespace outside the tag').
So, I did that... And it still didn't work. Which brings us to 2 bugs.

1/

I managed to find out that whitespace was just ignored, because Aeva Embedding is active, which adds noae tags around quotes right when they're being processed. So it will see another tag around it, and will consider there are no extra spaces, which is wrong. Possible fixes:

a) account for  being possibly there in the regex. This is what I'm doing for now. It seems to be working just fine, but I'm a bit worried it might make the regex slower. So, I added a ^ right before the noae test, so that it only does once, and ignores it if it fails. This should now make the regex actually faster than in SMF... Much faster, even, because it looks like the SMF code is actually looking for the entire rest of the string...?! Heck, this can't be possible, because that would be an awful bug. I just realized I'm not that well versed into BBC parsing these days. Used to be... But I forgot most of it.

b) Right when adding the noae tags, do the trimming at this instant. Because we know that a quote has to be trimmed, we can do that. However, if an admin decides that they don't want trimming, it'll still occur even if disabled in the BBC DB table... Hmm.

2/

Okay, I checked and double-checked, and can't seem to find the code that will trim outside spaces BEFORE the quote... There are two such tests, but it seems they both account for whitespace AFTER the tag... WTF?! If that's the case, then isn't it a bug, too...?



Also, I figured that it would also make sense to apply outside trimming to other 'special' block tags like code, and possibly media. What do you reckon[1]?
 1. I love this word. It's close to the French for "recognize", meaning that for years I misunderstood it... I think the first time I realized my mistake was when watching a Harry Potter movie with French subtitles and being surprised at the translation for the word.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: BBCode trimming issues?
« Reply #1, on March 21st, 2012, 11:17 AM »
Hmm, interesting.

The parser is a bit of a mess in some ways and possibly needs refactoring anyway...
When we unite against a common enemy that attacks our ethos, it nurtures group solidarity. Trolls are sensational, yes, but we keep everyone honest. | Game Memorial

Nao

  • Dadman with a boy
  • Posts: 16,079
Re: BBCode trimming issues?
« Reply #2, on March 21st, 2012, 11:22 AM »
Does that 'interesting' mean you'll look into it, or you're not feeling competent and would like me to keep investigating?
Just so I know what to work on right now... ;)

Oh, there's also the 'admin' folder creation thingy... Should we do it soon enough? The question would instead be: do you have any outstanding, uncommitted, admin-related files in your install? (I have none, myself. But it's likely you do.)
If yes, you might want to do the split yourself.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: BBCode trimming issues?
« Reply #3, on March 21st, 2012, 11:41 AM »
The whole thing's a mess generally and right now I have enough going on without unpicking the hundreds of lines of code involved, especially knowing full well there's a problem with the preparser right now.

So I'll look at it but not until after I've moved out and not until after I've had time to readjust and set everything up on my new dev environment (due to reasons of space, I'll be downsizing everything to a laptop immediately after moving) so that my existing PC/Mac are solely around for performance testing and thus do not need to be set up all the time.

Regarding the admin folder, the only thing I have is a template change where I tried out my admin-front-page-helpful-links thing but there's been suggestions about improving it and I haven't figured out how I want to do those so I never committed it.

Also, if we're moving files like that, we almost might as well break some of the templates up a touch since there's templates bundled together perhaps unnecessarily, e.g. Admin.template.php could be separate files for the different things it does?
Re: BBCode trimming issues?
« Reply #4, on March 29th, 2012, 12:56 AM »
There's actually a side issue now that I think about it with the /me tag, where it trims inner space when it shouldn't.