Let's say my ALT tag is "Here's me in Paris, France". This is what I would get:

<meta property="og:image" content="http://www.example.com/sites/default/files/MY_IMAGE.jpg, France" typeof="foaf:Image" class="img-responsive" />

Note the offending ", France" followed by the other <img> properties that should not be included.

The weird thing is that the image_src tag parses the url correctly.

For now I'm just avoiding using commas in the ALT tag, though that obviously isn't a long-term solution.

CommentFileSizeAuthor
#42 metatag-parse_img_url-2761909-42.patch1.06 KBplach
#40 metatag-parse_img_url-2761909.patch605 bytesplach
#36 metatag-correctly_parse_img_tags_containing_commas-2761909-36.patch1.99 KBgreenSkin
#35 metatag-correctly_parse_img_tags_containing_commas-2761909-35.patch1.75 KBgreenSkin
#32 metatag-correctly_parse_img_tags_containing_commas-2761909-30.patch2.08 KBandrewsuth
#29 metatag-correctly_parse_img_tags_containing_commas-2761909-29.patch1.99 KBandrewsuth
#24 interdiff-2761909-21-24.txt3.83 KBBoobaa
#24 metatag-correctly_parse_img_tags_containing_commas-2761909-24.patch2.02 KBBoobaa
#21 interdiff-2761909-12-21.txt542 bytesroshkovanv
#21 metatag-correctly_parse_img_tags_containing_commas-2761909-21.patch2.68 KBroshkovanv
#19 interdiff-2761909-12-19.txt533 bytesroshkovanv
#19 metatag-correctly_parse_img_tags_containing_commas-2761909-19.patch2.67 KBroshkovanv
#12 metatag-correctly_parse_img_tags_containing_commas-2761909-12.patch2.07 KBlmeurs
#9 metatag-n2761909-9.patch20.42 KBDamienMcKenna
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

seancasey created an issue. See original summary.

lukasss’s picture

I also had that problem!
I tested and concluded that the metatag is not being!
This is 99%

I'm getting this error with the module https://www.drupal.org/project/field_tokens

I am preparing a patch to fix it!

lukasss’s picture

Status: Active » Closed (works as designed)
seancasey’s picture

@lukasss, why did this issue get closed and marked as "works as designed"?

lukasss’s picture

I'm sorry. Dear @seancasey, change the issue as you see fit

DamienMcKenna’s picture

Status: Closed (works as designed) » Active
Issue tags: +Needs tests

I'm reopening this to fix image handling so it only looks at the SRC attribute of the IMG tag.

seancasey’s picture

Thanks, @DamienMcKenna.

Rather than just modifying the current og:image (and og:image_url) parsing code in the submodule, I would suggest just borrowing the way the image field gets parsed from the image_src tag in the metatag module. I believe that tag works fine, and it would be good for internal consistency to have the submodules parse the url from the image field in the same manner.

DamienMcKenna’s picture

Version: 8.x-1.0-beta9 » 8.x-1.x-dev
DamienMcKenna’s picture

Working on porting D7's image tests to D8. This is a copy/paste/rename-some-things first step, more to come.

Lukas von Blarer’s picture

Just faced this issue as well. Weird enough that the image_src metatag doesn't have this issue with the exact same tokens. Is this because og:image is set to be multi value?

DamienMcKenna’s picture

Status: Active » Postponed
Related issues: +#2628472: Write tests for image handling

Lets do the tests in #2628472: Write tests for image handling first and then work on fixing this.

lmeurs’s picture

@Lukas von Blarer: It indeed only happens to image metatags which may contain multiple values. MetaNameBase::parseImageURL() explodes $value by commas which may occur between tags as separator, but may also occur inside attributes or even outside image tags depending on whatever the field formatter returns.

I attached a patch which explodes by commas of they are actually between tags, but also I added a URL validator just to be sure. I guess there still are situations that are uncovered since the implementation heavily leans on comma separated tags which totally depends on the result of field formatters, but I hope the patch is a small improvement.

DamienMcKenna’s picture

Status: Postponed » Needs review

8.x-1.0 is out, so this is fair game again.

The last submitted patch, 9: metatag-n2761909-9.patch, failed testing.

Status: Needs review » Needs work
DamienMcKenna’s picture

Status: Needs work » Postponed
nkraft’s picture

hi! I'm experiencing the same issue -- any alt tag with a comma in it is causing the [node:field_image] token to not render the og:image tag correctly -- instead it outputs mangled html, like so:

<meta property="og:image" content="http://niams.iqscloud.net/sites/default/files/field/image/achilles_image-new.jpg, likely placing increased  strain on the Achilles tendon and rendering it more vulnerable to injury.&quot; typeof=&quot;foaf:Image&quot; itemprop=&quot;image&quot; /&gt;







" />

I'm not experienced at testing/fixing modules. We have a site about to go into Production, and this is proving to be a major issue for is. Any ideas on how i could remedy this (removing alt tags is not an option, and deleting all commas in thousands of alt tags also not an option.)

Thanks for any help you can provide.

idiaz.roncero’s picture

Hello;

I can report the same problem and field_tokens is not the issue because i'm not using it.

I'm using metatag 8.x-dev.

roshkovanv’s picture

@lmeurs, this will not work correctly if you have something like this:
"[node:field_image],http://my_site.example/themes/custom/my_theme/fallback_image.png" <- the path to a fallback image...

roshkovanv’s picture

roshkovanv’s picture

DamienMcKenna’s picture

@roshkovanv: Thanks for your work on this. As soon as #2628472: Write tests for image handling is finished I'll be able to review the implications of this, and improve the tests.

bkosborne’s picture

FYI, For those looking for a quick fix, you can avoid this issue entirely since #2611866: Add image style tokens for image fields was committed to the Token module. You can get the raw URL for an image style via tokens, instead of just getting the HTML markup of the image. In fact, maybe Meta Tag should indicate that in the description for such image fields, because it's not obvious you can use tokens like this (they don't appear in the token browser).

See the patch in the reference issue for the format for the token. This allows you to control the image style as well :)

Boobaa’s picture

Rerolled the patch from #21 (#2911435: Streamline the HTML output logic made it inapplicable). Now my og:image tag renders properly even if I use the original image from an image field which has an alt attribute containing comma(s) and I don't override anything in the token display mode.

_San_’s picture

Any plans to release the fix for this? If more development is needed, I'm willing to help.

DamienMcKenna’s picture

Status: Postponed » Needs review

Status: Needs review » Needs work
ZapevalovAnton’s picture

Patch #24 not work for me.

andrewsuth’s picture

Rerolled patch #24 for the latest metatag release (8-x-1.4).

DamienMcKenna’s picture

Status: Needs work » Needs review

Let's see what the testbot says.

Status: Needs review » Needs work
andrewsuth’s picture

andrewsuth’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
greenSkin’s picture

greenSkin’s picture

Missed the use statement for UrlHelper. Updated patch.

DamienMcKenna’s picture

Status: Needs work » Needs review

Let's run that one by the testbot.

Status: Needs review » Needs work
plach’s picture

Status: Needs work » Needs review
FileSize
605 bytes

I had created a patch for this bug before finding the issue, I'm posting it anyway, just in case it is deemed useful. Not to say this should be the new "official" patch to review now, just curious to see if the testbot likes it.

Status: Needs review » Needs work

The last submitted patch, 40: metatag-parse_img_url-2761909.patch, failed testing. View results

plach’s picture

Status: Needs work » Needs review
FileSize
1.06 KB

This should work better.

  • DamienMcKenna committed 7dba114 on 8.x-1.x authored by plach
    Issue #2761909 by roshkovanv, andrewsuth, greenSkin, plach, Boobaa,...
DamienMcKenna’s picture

Status: Needs review » Fixed
Issue tags: -Needs tests
Parent issue: » #3203686: Plan for Metatag 8.x-1.17

I committed #42. Thank you.

Status: Fixed » Closed (fixed)

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

vikicica22’s picture

This error has occurred again. Please investigate.
Drupal Version: 9.5.2
Metatag: 8.x-1.x-dev

DamienMcKenna’s picture

Please open a new issue and provide details of the errors that show on your site, your site's logs, etc that might help track down the problem.