Commit 8d92a2a4 authored by David Lesieur's avatar David Lesieur

Fixed handling of quoted strings.

parent 8bcc6b60
......@@ -34,21 +34,19 @@ function cck_facets_faceted_search_collect(&$facets, $domain, $env_id, $filter,
}
}
// TODO: Move this to faceted_search.inc, avoiding duplication in other modules (biblio_facets).
function _cck_facets_quoted_query_extract($keys, $option) {
// Based on search_query_extract, but keys terminate on a double-quote
// followed by a space rather than a single space.
if (preg_match('/(^| )'. $option .':(.*?")( |$)/i', $keys, $matches)) {
// Based on search_query_extract, but matching a quoted value. Double-quotes
// are allowed into the value when escaped with the backslash character.
if (preg_match('/(^| )'. $option .':"((\\\.|[^"])*?)"( |$)/i', $keys, $matches)) {
return $matches[2];
}
}
// TODO: Move this to faceted_search.inc, avoiding duplication in other modules (biblio_facets).
function _cck_facets_quoted_query_insert($keys, $option, $value = '') {
// Based on search_query_insert, but keys terminate on a double-quote followed
// by a space rather than a single space.
// Based on search_query_extract, but matching a quoted value. Double-quotes
// are allowed into the value when escaped with the backslash character.
if (search_query_extract($keys, $option)) {
$keys = trim(preg_replace('/(^| )'. $option .':(.*?)(" |$)/i', ' ', $keys));
$keys = trim(preg_replace('/(^| )'. $option .':"((\\\.|[^"])*?)"( |$)/i', ' ', $keys));
}
if ($value != '') {
$keys .= ' '. $option .':'. $value;
......
......@@ -22,7 +22,8 @@ function text_facets_cck_facets_collect(&$facets, $field, $domain, $env_id, $arg
// Scan the given search text for a '{field_name}:"{value}"'
// token, and create facets from it.
if ($found_text = _cck_facets_quoted_query_extract($arg, $field['field_name'])) {
$found_text = trim(strtr($found_text, '""', '"'), '"');
// Unescape the value.
$found_text = strtr($found_text, array('\"' => '"', '\\\\' => '\\'));
if (!empty($found_text)) {
// Create an active facet with the value found in the search text.
$category = new cck_facet_category($field, $found_text);
......@@ -61,8 +62,8 @@ class text_facet extends cck_facet {
function get_text() {
if ($category = $this->get_active_category()) {
// Enclose value in double-quotes and escape double-quotes within the value.
return '"'. strtr($category->_value, '"', '""') .'"';
// Quote and escape the value.
return '"'. strtr($category->_value, array('"' => '\"', '\\' => '\\\\')) .'"';
}
return '';
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment