Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comments
Comment #2
lukasss CreditAttribution: lukasss commentedI 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!
Comment #3
lukasss CreditAttribution: lukasss commentedComment #4
seancasey CreditAttribution: seancasey as a volunteer commented@lukasss, why did this issue get closed and marked as "works as designed"?
Comment #5
lukasss CreditAttribution: lukasss commentedI'm sorry. Dear @seancasey, change the issue as you see fit
Comment #6
DamienMcKennaI'm reopening this to fix image handling so it only looks at the SRC attribute of the IMG tag.
Comment #7
seancasey CreditAttribution: seancasey as a volunteer commentedThanks, @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.
Comment #8
DamienMcKennaComment #9
DamienMcKennaWorking on porting D7's image tests to D8. This is a copy/paste/rename-some-things first step, more to come.
Comment #10
Lukas von BlarerJust 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?
Comment #11
DamienMcKennaLets do the tests in #2628472: Write tests for image handling first and then work on fixing this.
Comment #12
lmeurs CreditAttribution: lmeurs commented@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.
Comment #13
DamienMcKenna8.x-1.0 is out, so this is fair game again.
Comment #16
DamienMcKennaNeed to finish #2628472: Write tests for image handling first.
Comment #17
nkrafthi! 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:
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.
Comment #18
idiaz.ronceroHello;
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.
Comment #19
roshkovanv CreditAttribution: roshkovanv commented@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...
Comment #20
roshkovanv CreditAttribution: roshkovanv commentedComment #21
roshkovanv CreditAttribution: roshkovanv at FFW commentedComment #22
DamienMcKenna@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.
Comment #23
bkosborneFYI, 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 :)
Comment #24
BoobaaRerolled 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 analt
attribute containing comma(s) and I don't override anything in thetoken
display mode.Comment #25
_San_ CreditAttribution: _San_ commentedAny plans to release the fix for this? If more development is needed, I'm willing to help.
Comment #26
DamienMcKennaComment #28
ZapevalovAnton CreditAttribution: ZapevalovAnton as a volunteer commentedPatch #24 not work for me.
Comment #29
andrewsuth CreditAttribution: andrewsuth at World Food Programme commentedRerolled patch #24 for the latest metatag release (8-x-1.4).
Comment #30
DamienMcKennaLet's see what the testbot says.
Comment #32
andrewsuth CreditAttribution: andrewsuth at World Food Programme commentedahh OK rerolled for 8.x-1.x-dev branch ..
Comment #33
andrewsuth CreditAttribution: andrewsuth at World Food Programme commentedComment #35
greenSkin CreditAttribution: greenSkin as a volunteer commentedRerolled patch from #32 for 8.x-1.16.
Comment #36
greenSkin CreditAttribution: greenSkin as a volunteer commentedMissed the
use
statement for UrlHelper. Updated patch.Comment #37
DamienMcKennaLet's run that one by the testbot.
Comment #40
plachI 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.
Comment #42
plachThis should work better.
Comment #44
DamienMcKennaI committed #42. Thank you.
Comment #46
vikicica22 CreditAttribution: vikicica22 commentedThis error has occurred again. Please investigate.
Drupal Version: 9.5.2
Metatag: 8.x-1.x-dev
Comment #47
DamienMcKennaPlease 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.