Page MenuHomePhabricator

Function applyDiffStyle uses regexes which do not detect CSS classes appropriately
Open, MediumPublic

Description

Working on this task requires knowledge of regular expressions in PHP.

Currently, the applyDiffStyle() function uses the regex
/(<[^>]+)class=(['\"])$class\\2([^>]*>)/
to try to detect the CSS classes.
This only works if the element has only one class and fails for some classes (mentioned on T36800) which appear at
https://en.wikipedia.org/w/index.php?title=Special:RecentChanges&feed=rss&action=purge
E.g.:

Something like
(<[^>]+)class=(['\"])$class(| .+?)\\2([^>]*>)
would be slightly better:
http://www.rubular.com/r/BGlcrGfRtd
but still wouldn't work in case there is some class before the specified class:
http://www.rubular.com/r/xLWx9MWBSL

Besides, notice that
\"
has only one backslash and
\\2
has two. I don't know what is the proper syntax for this in PHP strings but it is likely that one of the two needs to be fixed.

See also:

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 12:11 AM
bzimport set Reference to bz34801.
bzimport added a subscriber: Unknown Object (MLST).

I am new to mediawiki and foss.I would like to work on this bug as my first fix

i have found the solution, i am submitting a patch to review

Change 193081 had a related patch set uploaded (by Rits):
T36801 Changed Function applyDiffStyle uses regexes which do not detect CSS classes appropriately

https://gerrit.wikimedia.org/r/193081

Change 193081 abandoned by TTO:
T36801 Changed Function applyDiffStyle uses regexes which do not detect CSS classes appropriately

Reason:
No progress in 2 years.

https://gerrit.wikimedia.org/r/193081

subins2000 added a subscriber: subins2000.

I'd like to work on this

How shall I write the testcase ? I looked in phpunit/includes, but couldn't find any similar ones. Any pointers would be great, thanks

@subins2000 you can create a file in tests/phpunit/unit/includes/FeedUtilsTest.php

Then you'd want something like

<?php

class FeedUtilsTest extends MediaWikiUnitTestCase {

  public function testApplyDiffStyle() {
   $someTestString = 'blahblah';
   $this->assertSame( 'whatyouexpect', FeedUtils::applyDiffStyle( $someTestString) );
  }

}

You can run the individual test with vendor/bin/phpunit tests/phpunit/unit/includes/FeedUtilsTest.php

Change 576444 had a related patch set uploaded (by Subins2000; owner: Subins2000):
[mediawiki/core@master] Update regex to match classes appropriately

https://gerrit.wikimedia.org/r/576444

@kostajh Thank you for your help :) I've made a patch. Hope it's fine and up-to the standards.

Is Core's includes/FeedUtils.php Growth or Core Platform Engineering territory?
In any case this contributed patch has been waiting for a review for eight months now...

Is Core's includes/FeedUtils.php Growth or Core Platform Engineering territory?

Looking at commits to that file, I don't see anything from current or past Growth team members.

In any case this contributed patch has been waiting for a review for eight months now...

It would be nice to surface this patch and others like it to the broader community of developers with +2 rights. There are many patches like this that theoretically are supposed to fall into some team's purview due to Developers/Maintainers but in practice they don't get reviewed since they don't relate at all to the team's day-to-day work or quarterly goals.

Change 576444 merged by jenkins-bot:
[mediawiki/core@master] FeedUtils: Update regex to match classes appropriately, and test

https://gerrit.wikimedia.org/r/576444