Jump to content

Editing posts breaks filestore-agnostic URLs


Colonel_mortis
Go to solution Solved by Marc Stridgen,

Recommended Posts

To reproduce:

  • (Prerequisites: lazy loading is enabled (on by default), and the default disk storage location is used for attachments)
  • Attach an image to a post
  • Look at that post in the DB - it should look something like
    <img class="ipsImage ipsImage_thumbnailed" data-fileid="1" data-ratio="75.00" width="640" alt="foo.jpg" data-src="<fileStore.core_Attachment>/monthly_2022_10/foo.jpg" src="<___base_url___>/applications/core/interface/js/spacer.png" />
  • Edit the post (don't need to change anything)
    Look at the post again in the DB - it should now look something like
    <img alt="foo.jpg" class="ipsImage ipsImage_thumbnailed" data-fileid="1" data-ratio="75.00" width="640" data-src="<___base_url___>/uploads/monthly_2022_10/foo.jpg" src="<___base_url___>/applications/core/interface/js/spacer.png" />
  • Notice that the data-src has changed from <fileStore.core_Attachment>/monthly_2022_10/foo.jpg to <___base_url___>/uploads/monthly_2022_10/foo.jpg, so it is no longer agnostic of the backing file store

Moving the attachments filestore will now cause these images to point to the wrong place.

This is because in \IPS\Text\Parser::_parseImgElement, you have

		/* Lazy-loaded? */
		$srcAttribute = ( $element->hasAttribute( 'src' ) AND $element->hasAttribute( 'data-src' ) ) ? 'data-src' : 'src';

		// ...

		/* Or an attachment? */
		elseif ( $attachment = static::_getAttachment( $element->getAttribute($srcAttribute ), $element->hasAttribute('data-fileid') ? $element->getAttribute('data-fileid') : NULL ) )
		{
			$file = $this->_getFile( 'core_Attachment', $element->getAttribute( $srcAttribute ) );

			$element->setAttribute( 'data-fileid', $attachment['attach_id'] );
			$element->setAttribute( 'src', str_replace( array( 'http:', 'https:' ), '', str_replace( static::$fileObjectClasses['core_Attachment']->baseUrl(), '{fileStore.core_Attachment}', $element->getAttribute( $srcAttribute ) ) ) );

the last line there is setting the 'src' attribute, when in fact it should be setting $srcAttribute. The src attribute is subsequently discarded to replace with the lazy load placeholder.

This works for new posts because $srcAttribute is 'src' there, but when editing posts (with lazy loading enabled) it is actually data-src.

Link to comment
Share on other sites

Thank you for bringing this issue to our attention! I can confirm this should be further reviewed and I have logged an internal bug report for our development team to investigate and address as necessary, in a future maintenance release.

 

Link to comment
Share on other sites

  • 2 months later...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...