When I add a link like http://drupal.org in body text, it changes to something like:
http://photos/city1/org/1/313412664beb1cbb3ea7fe7f3f3a11f4.jpgphotos/city1/org/1/f59035a8a2bd3ce0ab9cc018f5fbe00f.jpgphotos/city1/org/1/36ae4bce20c0d635788778f804fe059b.jpgdrupal.org
For some reason the paths of files from field 'photos' from the same node are inserted between http:// and the rest of the link.

The actual path where files are stored is:
files/0photos/city1/org/1/313412664beb1cbb3ea7fe7f3f3a11f4.jpg

The replacement is performed in _filefield_paths_replace_path

Commenting line 299 $item['value'] = preg_replace("/$regex/e", $replacement, $item['value']);
fixes the problem.

Why this replacement happening? Is it safe to comment the line?

Comments

Pablo Gosse’s picture

You shouldn't comment out that line as it's what converts the old path to whatever the new pattern is (defined by the $old and $new parameters).

What are the settings you have defined for FFP on the field in question (file path, file name, and the options for both of these)?

A good way to debug would be to step through the code and grab the value of $regex, and outside of Drupal test the generated regex against the original data in $item['value'] (so before the line you reference above) using an external script or a regex tool such as RegExr - http://gskinner.com/RegExr/.

This will show you the match that will be evaluated in preg_replace and should help isolate the problem.

Pablo

Budrick’s picture

File path
0photos/[node:field_city]/[node:content-type:machine-name]/[node:nid]
File name
[random:hash:md5].[file:ffp-extension-original]
Cleanup and transliteration are off for both

The line is called for 5 text fields including body
The regexp for body is:
(http:\/\/sauna.kz\/sites\/sauna\/files\/b844b26de6cd0e4e149b680d7993724a.jpg|\/sites\/sauna\/files\/b844b26de6cd0e4e149b680d7993724a.jpg|:\/\/)(styles\/.*?\/\/|)()

http://gskinner.com/RegExr
shows that this regexp changes "http://drupal.org" to "http[[://://]]drupal.org"

deciphered’s picture

Status: Active » Postponed (maintainer needs more info)

Your regex doesn't look right, it appears to be out of order.

Yours is this:
(http:\/\/sauna.kz\/sites\/sauna\/files\/b844b26de6cd0e4e149b680d7993724a.jpg|\/sites\/sauna\/files\/b844b26de6cd0e4e149b680d7993724a.jpg|:\/\/)(styles\/.*?\/\/|)()

But it should be this (or similar):
(http:\/\/sauna.kz\/sites\/sauna\/files\/|\/sites\/sauna\/files\/|public:\/\/)(styles\/.*?\/public\/|)(b844b26de6cd0e4e149b680d7993724a.jpg)

The obvious things to point out there is the lack of the 'public' and the file being in the wrong place, hence the breakage.

Can you test with the latest dev (or even better the latest Git commit) and let me know if the regex is still weird? Also, try on a fresh copy of Drupal, because it's possible that it's a setting oddity related to your public file system.

sin’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

Hi!

I'm helping Budrick with this issue on sauna.kz. I can confirm it is fixed in latest Git. $regex looks like this:

(http:\/\/sauna.kz\/sites\/sauna\/files\/|\/sites\/sauna\/files\/|public:\/\/)(styles\/([a-z0-9\-_\/]*?)\/public\/|)(626e6bc2b764d03c31e151102c8ea6bc.JPG)(\?(\S+?&|)itok=(\S{8})|)