Issue 2934596 broke matching of media tags for me. I have blocks with tags like this:

[[{"type":"media","view_mode":"media_original","fid":"7","attributes":{"alt":"","class":"media-image","height":"148","typeof":"foaf:Image","width":"300"}}]]

which are not matched by the new regex because there are no characters between the { and the quote. Changing the regex to this:

define('MEDIA_WYSIWYG_TOKEN_REGEX', '/\[\[\{.*?"type":"media".+?\}\]\]/s');

fixes the problem.

I am using PHP Version 7.0.22-0ubuntu0.16.04.1.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

MartinTomes created an issue. See original summary.

joseph.olstad’s picture

joseph.olstad’s picture

Status: Active » Reviewed & tested by the community

mentioned code will be reverted, publish 2.16 release with this revert.

joseph.olstad’s picture

Status: Reviewed & tested by the community » Needs review

actually, I reviewed this again, the issue summary makes no sense because it says to put the same regex as already is in 2.15
very confused
also, I tested media_dev using 2.15 in simplytest.me and there were no issues with the regex that I could find.

I will run some more tests on a site with 2.14 with some test data and try upgrading to 2.15 and see what happens.

joseph.olstad’s picture

If this is indeed still an issue, could you make a patch? it'd be easier to review to see the before and after.

joseph.olstad’s picture

here's a test I ran
https://dcg8.ply.st/node/1

link is good from now until 12 hours from now.

adriancotter’s picture

This is an issue for me...
One important note -- it only seems happens in blocks. Media content in nodes seems fine as far as I have been able to find.
EDIT --> this might just be the fact that the content in blocks is older and was still using some older syntax?!

The media item does also appears fine in the WYSIWYG, it is just not getting rendered on the front end. I tried adding spaces in the media notation but that did not help matters.

This is an example of one that is inside a BLOCK and is NOT working. This was a PREEXISTING media item
If I add a new one, it appears as the one working below...
[[{"type":"media","view_mode":"media_large","fid":"2397","link_text":null,"field_deltas":{"1":{}},"fields":{},"attributes":{"style":"width: 500px; height: 63px;","class":"media-image media-element file-media-large","id":"styles-0-0","data-delta":"1"}}]]

This is a one that inside a NODE and is working :
[[{"fid":"3321","view_mode":"default","fields":{"format":"default","field_file_image_alt_text[und][0][value]":false,"field_file_image_title_text[und][0][value]":false,"field_photographer[und][0][value]":"","field_caption[und][0][value]":"","field_permissions[und][0][value]":""},"link_text":null,"type":"media","field_deltas":{"1":{"format":"default","field_file_image_alt_text[und][0][value]":false,"field_file_image_title_text[und][0][value]":false,"field_photographer[und][0][value]":"","field_caption[und][0][value]":"","field_permissions[und][0][value]":""}},"attributes":{"class":"media-element file-default","data-delta":"1"}}]]

I was able to fix by just re-picking the image for the various effected blocks -- but it would nice if the old images were rendered as well -- I'm sure I missed some. If i have time tomorrow, I'll try and dig out the REGEX and have a look.

koosvdkolk’s picture

The latest update breaks all our media tags, everywhere :-(

alrh’s picture

The suggested change in the regex is: replacing the first .+? with .*? (matching 0 or more characters between [[{ and "type":"media" instead of 1 or more).

hcethatsme’s picture

Breaks all our media tags too, for the same reason: they start [[{"type":"media". When I insert a space between [[{ and "type", bingo, it's fine. alrh's fix works for us!

joseph.olstad’s picture

would be faster if someone had made a patch the first time.
here's a patch as discussed above.

joseph.olstad’s picture

Status: Needs review » Fixed
joseph.olstad’s picture

I wouldn't be surprised to hear about more people complaining about the latest regex regression fix.
I hesitated to change this regex in the first place. It was working well enough before but the related issue came up and I thought ya maybe it'd be good to support the edge case too but ya, got bit again by this.

joseph.olstad’s picture

anyhow, new release , 2.16 with the patch 11
also 3.0-rc2

MartinTomes’s picture

Thanks for putting this fix in.

koosvdkolk’s picture

Thanks a lot indeed, Joseph!

joseph.olstad’s picture

Hopefully this latest change holds up well in the real world. Thanks everyone for the timely responses.

Media keeps getting better and better

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

weseze’s picture

I have experienced a site with the following token:

[[{"fid":"115","view_mode":"default","attributes":{"alt":"Opame","title":"Opname","height":"178","width":"268","style":"width: 261px; height: 178px;","class":"media-element file-default"},"fields":{"format":"default","field_file_image_alt_text[und][0][value]":"Opame","field_file_image_title_text[und][0][value]":"Opname"},"type":"media"}]]

It doesn't get replaced because it contains "type":"media"}]] at the very end and that does not match the regex:

\[\[\{.*?"type":"media".+?\}\]\]

If I replace the regex with:

\[\[\{.*?"type":"media".*?\}\]\]

It does get replaced.

Any thoughts?

I can work arround this issue by just resaving all nodes that contain these tokens, but in an automated update flow this does not work :)

joseph.olstad’s picture

Status: Closed (fixed) » Needs review

Thanks for your detailed report and analysis.

needs review, perhaps @kaare could weigh in on this?

The regex has been adjusted quite a few times to accomodate various configurations and support various configurations of other contrib modules. It looks like there's an opportunity for improvement here.

This very small change proposed may be appropriate however it needs some review.

@weseze is proposing changing this:

\[\[\{.*?"type":"media".+?\}\]\]

to this:

\[\[\{.*?"type":"media".*?\}\]\]
joseph.olstad’s picture

Version: 7.x-2.15 » 7.x-2.19
joseph.olstad’s picture

joseph.olstad’s picture

Status: Closed (outdated) » Fixed

see these commits in dev
fixed in 2.x / 3.x and 4.x dev branches

Issue #2942482 AND Issue #2976467 by shivamitakari, MartinTomes, koosvdkolk, .

https://cgit.drupalcode.org/media/commit/?h=7.x-3.x&id=412234c749d65d9e6...

and

https://cgit.drupalcode.org/media/commit/?h=7.x-4.x&id=ad9e3b55066be4fa8...

If all goes well and no reported regressions then this change will make it into the next release of Media 7.x-2.x / 7.x-3.x and 7.x-4.x

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.