diff --git a/filefield_paths.module b/filefield_paths.module index c342411..bcfb9fc 100644 --- a/filefield_paths.module +++ b/filefield_paths.module @@ -281,7 +281,7 @@ function filefield_paths_file_presave($file) { function _filefield_paths_replace_path($old, $new, $entity) { // Build regular expression. $info = parse_url(file_stream_wrapper_uri_normalize($old)); - $info['path'] = !empty($info['path']) ? $info['path'] : ''; + $info['path'] = !empty($info['path']) ? str_replace('[', '\[', str_replace(']', '\]', $info['path'] ) ) : ''; $absolute = str_replace("{$info['host']}{$info['path']}", '', file_create_url($old)); $relative = parse_url($absolute, PHP_URL_PATH); $regex = str_replace('/', '\/', "({$absolute}|{$relative}|{$info['scheme']}://)(styles/.*?/{$info['scheme']}/|)({$info['host']}{$info['path']})"); @@ -296,7 +296,18 @@ function _filefield_paths_replace_path($old, $new, $entity) { if ($field['module'] == 'text' && isset($entity->{$field['field_name']}) && is_array($entity->{$field['field_name']})) { foreach ($entity->{$field['field_name']} as &$language) { foreach ($language as &$item) { - $item['value'] = preg_replace("/$regex/e", $replacement, $item['value']); + $newval = preg_replace("/$regex/e", $replacement, $item['value']); + if (!is_null($newval)) { + $item['value'] = $newval; + } + else { + $args = array( + '@value' => $item['value'], + '@regex' => $regex, + '@replacement' => $replacement, + ); + watchdog('filefield_paths', 'Error in preg_replace(\"/@regex/e\", "@replacement", @value)', $args, WATCHDOG_ERROR, $link = NULL); + } } } }