I'm noticing that the query generated for my view changes when I have a taxonomy term that includes a space in the name. For example, the url http://mysite.com/foo/One Term, generates the following where clause in the query:


WHERE (( (node.status = '1') AND (taxonomy_term_data_taxonomy_index__taxonomy_term_data.name IN ('One', 'Term')) ))
ORDER BY node_created DESC

However, shouldn't this build the where clause to say


WHERE ( (node.status = '1') AND (node.type IN ('facilities', 'parks') AND (taxonomy_term_data_taxonomy_index__taxonomy_term_data.name IN ('One Term') ) ))
ORDER BY node_created DESC
?

I have my view set up to accept multiple arguments, and I have also enabled replacing spaces with dashes, but neither of these should affect the generation of the one term, right?

Any help would be greatly appreciated.

Thank you!

CommentFileSizeAuthor
#13 1153370-fix-phrase-string.patch1.28 KBdawehner
#4 view_example.txt4.13 KBAnonymous (not verified)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

merlinofchaos’s picture

Status: Active » Fixed

That's because spaces get translated to + by the URL and the + is the OR separator.

Your URL needs to contain %20 for the space, which is the HTML entity for a space.

Anonymous’s picture

Hi, thanks for the quick reply. Actually, there is a %20 in the url, I removed it for readability sake.

When I use %20 in the Auto Preview of the view, for example One%20Term, the where clause returns:

WHERE (( (node.status = '1') AND (taxonomy_term_data_taxonomy_index__taxonomy_term_data.name = '-1') ))

Any idea why a -1 is returned and not the term? Could someone point me in the direction of where that query is generated?

Thanks so much.

merlinofchaos’s picture

Issue tags: -taxonomy, -views

Issue tags: taxonomy, terms with space in the word, views

There is a giant link pointing to the guidelines for issue tags. PLEASE READ THEM BEFORE TYPING RANDOM TAGS into the field. Please respect our processes on drupal.org.

Any idea why a -1 is returned and not the term? Could someone point me in the direction of where that query is generated?

The entirety of Views is a query generator. Specifically that part of a query is going to be generated by an argument handler for the argument you're using, and it could be affected by the argument validation plugin.

Since you didn't attach an export of the view, I can't tell you why that data gets transformed into a -1. I can't think of anything that should convert that to a -1. Perhaps there is a bug with transforming them, perhaps you've got something configured badly. Hard to say.

Anonymous’s picture

FileSize
4.13 KB

I'm sorry about the issue tags, it won't happen again.

I went ahead and attached a very basic view export that uses the same taxonomy filter to display an html list. It is set up to accept multiple arguments. The multiple arguments works just fine, until you introduce a taxonomy term that has a space (%20) in it.

Ex... (Foo,Bar) works fine, but (Foo,Bar,Two%20Words) does not.

Additionally, I am using CTools 7.x-1.0-alpha4 with Views 7.x-3.0-beta3.

Thanks again for your time.

merlinofchaos’s picture

Sorry, I shouldn't have been so forceful about the issue tags. Built up reaction; lots of people do it and I overreacted on this one. I'll try to be more polite on that in the future.

My guess is there's a bug with the string separation. Can you turn that feature off and try it? I bet the -1 will not appear.

Anonymous’s picture

No worries, I should have read it to begin with.

You are right, when I disable multiple values, it works just fine for one taxonomy value with a space in the name.

The view I am trying to build, obviously, needs the multiple terms. I'll see what I can do in terms of a fix, but I'm pretty new to the D7 code, so finding it might take me a bit.

Thanks again for your patience!

merlinofchaos’s picture

You can use multiple values as multiple arguments by selecting the option that allows multiple arguments that work together. That could be a workaround but you'll be limited in how many you can use.

dawehner’s picture

Status: Fixed » Active

It could be that the views_break_string method has a bug here.

Let's check this first.

dawehner’s picture

The break_string phase returns -1 if there is no valid input.

But at least until now " " or "+" breaks the string to OR and "," to AND.

The bug of this issue seems to be that " " breaks, but it shouldn't. I don't really see this.

An additional behaviour i see is that if you input "foo,bar" you get a execution runtime error.

Anonymous’s picture

I think I've narrowed it down to the function views_break_phrase_string() in /includes/handlers.inc.

if (preg_match('/^(\w+[+ ])+\w+$/', $str)) {
    // The '+' character in a query string may be parsed as ' '.
	$handler->operator = 'or';
    $handler->value = preg_split('/[+ ]/', $str);
  }
  else if (preg_match('/^(\w+,)*\w+$/', $str)) {
	$handler->operator = 'and';
	$handler->value = explode(',', $str);
  }

This either breaks up the string incorrectly, or skips the statement completely when it shouldn't. I'm still trying to get a handle on what the regex is doing, so hopefully I'll have more soon.

dawehner’s picture

That's interesting, i did quite some testing in code for this, see this:

  function test_views_break_phrase_string() {
    $empty_stdclass = new stdClass();
    $empty_stdclass->operator = 'or';
    $empty_stdclass->value = array();

    $null = NULL;
    // check defaults
    $this->assertEqual($empty_stdclass, views_break_phrase_string('', $null));

    $handler = views_get_handler('node', 'title', 'argument');
    $this->assertEqual($handler, views_break_phrase_string('', $handler));

    // test ors
    $this->assertEqualValue(array('word1', 'word2', 'word'), views_break_phrase_string('word1 word2+word', $handler));
    $this->assertEqual('or', $handler->operator);
    $this->assertEqualValue(array('word1', 'word2', 'word'), views_break_phrase_string('word1+word2+word', $handler));
    $this->assertEqual('or', $handler->operator);
    $this->assertEqualValue(array('word1', 'word2', 'word'), views_break_phrase_string('word1 word2 word', $handler));
    $this->assertEqual('or', $handler->operator);
    $this->assertEqualValue(array('word1', 'word2', 'word'), views_break_phrase_string('word1 word2++word', $handler));
    $this->assertEqual('or', $handler->operator);

    // test ands.
    $this->assertEqualValue(array('word1', 'word2', 'word'), views_break_phrase_string('word1,word2,word', $handler));
    $this->assertEqual('and', $handler->operator);
    $this->assertEqualValue(array('word1', 'word2', 'word'), views_break_phrase_string('word1,,word2,word', $handler));
    $this->assertEqual('and', $handler->operator);
dawehner’s picture

tested with node: title


$view = new view;
$view->name = 'test';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'test';
$view->core = 7;
$view->api_version = '3.0-alpha1';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'test';
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'node';
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['title']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 0;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 0;
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
$handler->display->display_options['fields']['title']['link_to_node'] = 1;
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Contextual filter: Content: Title */
$handler->display->display_options['arguments']['title']['id'] = 'title';
$handler->display->display_options['arguments']['title']['table'] = 'node';
$handler->display->display_options['arguments']['title']['field'] = 'title';
$handler->display->display_options['arguments']['title']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['title']['default_argument_skip_url'] = 0;
$handler->display->display_options['arguments']['title']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['title']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['title']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['title']['glossary'] = 0;
$handler->display->display_options['arguments']['title']['limit'] = '0';
$handler->display->display_options['arguments']['title']['transform_dash'] = 0;
$handler->display->display_options['arguments']['title']['break_phrase'] = 1;
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 0;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'test';
$translatables['test'] = array(
  t('Master'),
  t('test'),
  t('more'),
  t('Apply'),
  t('Reset'),
  t('Sort by'),
  t('Asc'),
  t('Desc'),
  t('Items per page'),
  t('- All -'),
  t('Offset'),
  t('All'),
  t('Page'),
);

It worked fine.

Back to your input:

Ex... (Foo,Bar) works fine, but (Foo,Bar,Two%20Words) does not.

That's currently how it is. You can either split by comma OR by space, which means AND or OR.

Perhaps the "," seperator should come first and ignore the comma.

dawehner’s picture

Status: Active » Needs review
FileSize
1.28 KB

Here is a patch which fixes the issue for me + a changed test.

dawehner’s picture

Status: Needs review » Fixed

Commited to 6.x-3.x and 7.x-3.x because the simpletest are running fine.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.