We are using a custom content type and have metatags set up as needed.

Either setting default or on a per content type basis the following occurs:

image_src: '[node:bsp_header:entity:bsp_media:entity:field_media_image]'

Returned metatag:

image_src: '/link-to-image'

However if the same token is added to og:image:

og:image: '[node:bsp_header:entity:bsp_media:entity:field_media_image]'

Returned metatag:

org:image: 'site-url/link-to-image'

Also if you add [site:url] to image_src it will be stripped out as well. No workaround ATM.

It would appear that image_src will always return a relative url path.

Issue fork metatag-3349990

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

glynster created an issue. See original summary.

damienmckenna’s picture

Issue tags: +Needs tests

Thank you for reporting the bug.

Have you tried other image meta tags, e.g. og:image_url, og:image:secure_url, twitter:image, etc?

glynster’s picture

@DamienMcKenna

Adding og:image_url or og:image:secure_url in the image_src field unsets the tag altogether. I assume this could be the order in which they are generated? Advanced first

URLS that render:
[node:url]
[site:url]

If I add the following:

[site:url][node:bsp_header:entity:bsp_media:entity:field_media_image]

Returned metatag:

image_src: '/link-to-image'

But added with just the [site:url]

image_src: 'site-url'

What else can I supply?

damienmckenna’s picture

Title: Drupal 10 image_src converts to relative link » image_src converts to relative link

That's weird - adding a value to og:image:url or og:image:secure_url shouldn't affect og:image at all. Are you using any other modules that relate to OpenGraph?

glynster’s picture

StatusFileSize
new29.29 KB

Sorry I misunderstood what you said. The other metatag fields all work as they should including og:image_url, og:image:secure_url, twitter:image. The issue is isolated to the advanced img_src. Somehow that is being adjusted.

We are not using any other additional modules that relate to OpenGraph. Again the issue is related only to the advanced (Generic) metatag img_src section. Please see screenshot.

glynster’s picture

Okay so I think this might be a Drupal core issue?

it is a link and not meta in the head:
<link rel="image_src" href="/sites/default/files/2023-03/header_locations.jpg">

damienmckenna’s picture

I don't see anything in core related to image_src. Might it come from another module, or maybe the theme?

glynster’s picture

This is definitely related to metatag as the url always updates when I update the Advanced image field within meta. I just set core Claro theme and the same result 'realtive url'. However in the global metatag section we have:

[site:url]sites/default/files/2023-03/organization.jpg

That renders fine as an absolute. If you add 2 tokens then it strips the [site:url]. What is odd is that if I add this to the other image urls all is good.

Sorry not helping much am I!

glynster’s picture

I also disabled the Schema module just in case it was getting in the way.

kruser’s picture

I'm seeing weird results with this. For example, using this same token in all the image meta fields: [node:field_social_media_image]

I get different results in the output:

<link rel="image_src" href="test image.jpg" />  (missing site URL and directory path)

<meta property="og:image" content="https://www.site.org/sites/default/files/test%20image.jpg" /> (works)

<meta property="og:image:url" content="https://www.site.orgtest image.jpg" />  (missing directory path)

<meta property="og:image:secure_url" content="https://www.site.orgtest image.jpg" />  (missing directory path)

<meta name="twitter:image" content="https://www.site.org/sites/default/files/test%20image.jpg" /> (works)
junkuncz’s picture

StatusFileSize
new448 bytes

Looks like the reason of wrong image_src attribute is an incomplete Plugin annotation. Setting the "absolute_url" = TRUE gives the ability to output() function (/src/Plugin/metatag/Tag/MetaNameBase.php line 529 in version 2.0.0) to build an absolute url.

Patch is attached.

I don't know what about og:image:url and og:image:secure_url most probably it's a different issue.

junkuncz’s picture

Version: 8.x-1.22 » 2.0.x-dev
Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 11: metatag-image_src-3349990-11.patch, failed testing. View results

junkuncz’s picture

Upps! :( Unfortunately I have no time to fix the tests and I'm quite sure it's not because of this one line change. (Error: Call to undefined method PhpParser\Node\Name::getParts() -> seems like something is missing there).

fago’s picture

https://www.drupal.org/node/640498/qa shows also two fails at 1.x, but shows green tests on 7.4. So let's try that.

Patch seems simple enough, so let's do this.

junkuncz’s picture

"drupal/metatag dev-2.0.x requires php >=8.0 -> your php version (7.4.28) does not satisfy that requirement."
Looks like no chance without php8.

damienmckenna’s picture

I'm rerunning the 2.0.x tests as they haven't ran in a while, it seems like they stem from the WebProfiler tests, which I'm considering removing anyway; we'll see what they say shortly: https://www.drupal.org/pift-ci-job/2824531

damienmckenna’s picture

The 2.0.x tests are currently failing, so I'm removing the Devel and WebProfiler tests: #3408825: Remove Devel, WebProfiler tests

damienmckenna’s picture

Status: Needs work » Needs review

I committed #3408825 so the tests for this should pass now.

taran2l made their first commit to this issue’s fork.

taran2l’s picture

damienmckenna changed the visibility of the branch 3349990-imagesrc-converts-to to hidden.

damienmckenna’s picture

I'm a little surprised at this test failure:

---- Drupal\Tests\metatag\Functional\MetatagXssTest ----
Status      Duration Info                                                                               
--------------------------------------------------------------------------------------------------------
Fail         16.523s testXssMetatagConfig                                                            
Fail         16.858s testXssEntityOverride                                                           
Pass         14.465s testXssEntityTitle                                                              
Pass         15.505s testXssEntityBody                                                               
damienmckenna’s picture

taran2l’s picture

I think it's because XSS string is discraded as not correct URL ... and there is no image_src metatag at all.

I think the options are:

  • adjust test to assert the new bahevior
  • remove test, as URL processing is core and we should not test it
  • find a new string that could create XSS but is not completely discarded

damienmckenna’s picture

Status: Needs review » Fixed

Committed. Thank you.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

taran2l’s picture

Thanks