Make WordPress Core

Opened 9 years ago

Closed 8 years ago

Last modified 8 years ago

#40861 closed defect (bug) (fixed)

REST API saves attachments with absolute path for `_wp_attached_file` on Windows platforms

Reported by: redcastor Owned by: SergeyBiryukov
Priority: normal Milestone: 4.9.8
Component: REST API Version: 4.6
Severity: normal Keywords: has-patch needs-unit-tests
Cc: Focuses:

Description

On windows, create media with rest api insert the meta "_wp_attached_file" not correctly.
It save the absolute path and not the relative path.

the function "wp_slash" add backslash in windows file path.

file: class-rest-attachements-controller.php
line: 150

<?php
$id = wp_insert_post( wp_slash( (array) $attachment ), true );

Attachments (2)

40861.patch​ (480 bytes ) - added by ocean90 9 years ago.
40861.2.patch​ (983 bytes ) - added by ocean90 9 years ago.

Download all attachments as: .zip

Change History (16)

This ticket was mentioned in ​Slack in #core by bobbingwide. ​View the logs.


9 years ago

#2 @bobbingwide
9 years ago

This bug causes a problem with Gutenberg. See ​https://github.com/WordPress/gutenberg/issues/5332

#3 @SergeyBiryukov
9 years ago

  • Milestone Awaiting Review → 5.0

#4 @ocean90
9 years ago

  • Keywords needs-patch added
  • Summary Rest Api create media → REST API saves attachments with absolute path for `_wp_attached_file` on Windows platforms
  • Version 4.7.5 → 4.6

~Looks like _wp_relative_upload_path() is missing here.~

Version 1, edited 9 years ago by ocean90 (previous) (next) (diff)

@ocean90
9 years ago

@ocean90
9 years ago

#5 @ocean90
9 years ago

  • Keywords has-patch needs-unit-tests added; needs-patch removed

Attached 40861.patch​ and 40861.2.patch​.

Since wp_insert_post() expects slashed data we should unslash the file argument as well, done in 40861.patch​.

In 40861.2.patch​ I switched to wp_insert_attachment() so the file argument doesn't get slashed in the first place.

#6 follow-up: @bobbingwide
9 years ago

The second patch makes it a lot more obvious that it's difficult to use the REST API to create an attachment which is actually attached to something! Is that one of the reasons for the 'rest_insert_attachment' action hook?

#7 in reply to: ↑ 6 @ocean90
9 years ago

Replying to bobbingwide:

The second patch makes it a lot more obvious that it's difficult to use the REST API to create an attachment which is actually attached to something!

Not sure I'm following. wp_insert_attachment() is a simple wrapper for wp_insert_post() without any additional filters. What's the issue you're seeing here?

#8 @danielbachhuber
8 years ago

  • Milestone 5.0 → 4.9.7

Let's land this in 4.9.7 so we can see this sooner rather than later.

#9 @ocean90
8 years ago

  • Milestone 4.9.7 → 4.9.8

4.9.7 has been released, moving to next milestone.

This ticket was mentioned in ​Slack in #core by pbiron. ​View the logs.


8 years ago

This ticket was mentioned in ​Slack in #core by pbiron. ​View the logs.


8 years ago

This ticket was mentioned in ​Slack in #core by jon_bossenger. ​View the logs.


8 years ago

#13 @SergeyBiryukov
8 years ago

  • Owner set to SergeyBiryukov
  • Resolution → fixed
  • Status new → closed

In 43529:

REST API: Ensure attachments created with WP_REST_Attachments_Controller::create_item() on Windows have a relative path.

Props ocean90, SergeyBiryukov, redcastor.
Fixes #40861.

#14 @SergeyBiryukov
8 years ago

In 43530:

REST API: Ensure attachments created with WP_REST_Attachments_Controller::create_item() on Windows have a relative path.

Props ocean90, SergeyBiryukov, redcastor.
Merges [43529] to the 4.9 branch.
Fixes #40861.

Note: See TracTickets for help on using tickets.