Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#1774 closed Bug (fixed)

Tracker can't deal with URLs of type something?param[]=1&param[]=2

Reported by: Ilinsekt Owned by:
Priority: normal Milestone: Piwik 1.1
Component: Core Keywords:
Cc: Sensitive: no

Description

If a URL is of type something?param[]=1&param[]=2, only the last param is recorded and stored in the database (first highlighted line in the screenshot). Following patch needs to be applied to fix this (description fits on trunk-r3248, fix in second highlighted line):

* core/Tracker/Action.php
  modify function excludeQueryParametersFromUrl(), replace:
  $validQuery .= $name.'='.$value.$separator;
  with:
  if (is_array($value))
  {
    foreach ($value as $param)
    {
      $validQuery.=$name.'%5B%5D='.$param.$separator;
    }
  }
  else
  {
    $validQuery .= $name.'='.$value.$separator;
  }

Attachments (3)

piwik_tracker_bug.png (71.9 KB) - added by Ilinsekt 3 years ago.
piwik_url1.png (168.3 KB) - added by Ilinsekt 3 years ago.
piwik_url2.png (130.0 KB) - added by Ilinsekt 3 years ago.

Download all attachments as: .zip

Change History (12)

Changed 3 years ago by Ilinsekt

comment:1 Changed 3 years ago by Ilinsekt

addition: apparently the piwik.js is partly responsible, so in the patch above, '%5B%5D=' needs to be replaced with '[]=', also following patch needs to be applied:

* js/piwik.js
  Bugfix, related to the above.
  modify function getRequest, replace:
  '&url=' + escapeWrapper(isDefined(configCustomUrl) ? configCustomUrl : locationHrefAlias) +
  with:
  '&url=' + escapeWrapper(isDefined(configCustomUrl) ? configCustomUrl : unescapeWrapper(locationHrefAlias)) +

comment:2 Changed 3 years ago by vipsoft (robocoder)

  • Resolution set to fixed
  • Status changed from new to closed

(In [3257]) fixes #1774 - patch by Ilinsekt; also added unit tests

comment:3 Changed 3 years ago by vipsoft (robocoder)

  • Milestone set to 1.1 - Piwik 1.1

comment:4 Changed 3 years ago by Ilinsekt

Thanks, but you forgot to read my comment posted later. locationHrefAlias in piwik.js is basically window.location.href, which is partly urlencoded and is urlencoded again in getRequest(). This results in param%5B%5D being the param name in Piwik, and since core/Common.php-> getArrayFromQueryString() only checks for [], the last param overwrites all the previous. The Action.php is related, without the patch we have param=Array put in the database.

I did not notice that earlier, as the bug in piwik.js only occurs after submitting a form (otherwise it apparently uses configCustomUrl, which does not seem to be urlencoded), and I tested the patch to Action.php simply by refreshing the page.

Here's the final patch:

* core/Tracker/Action.php
  modify function excludeQueryParametersFromUrl(), replace:
  $validQuery .= $name.'='.$value.$separator;
  with:
  if (is_array($value))
  {
    foreach ($value as $param)
    {
      $validQuery.=$name.'[]='.$param.$separator;
    }
  }
  else
  {
    $validQuery .= $name.'='.$value.$separator;
  }
  
* js/piwik.js
  modify function getRequest, replace:
  '&url=' + escapeWrapper(isDefined(configCustomUrl) ? configCustomUrl : locationHrefAlias) +
  with:
  '&url=' + escapeWrapper(isDefined(configCustomUrl) ? configCustomUrl : unescapeWrapper(locationHrefAlias)) +

Sorry for the inconvenience.

comment:6 Changed 3 years ago by Ilinsekt

Seriously, it won't work without the javascript patch. I have attached some screenshots to demonstrate.

Changed 3 years ago by Ilinsekt

Changed 3 years ago by Ilinsekt

comment:7 Changed 3 years ago by vipsoft (robocoder)

I'm not ignoring piwik.js ... I just haven't had time to analyze all the implications and code a fix yet.

Calling unescapeWrapper changes the semantics of some URLs which is why I haven't applied your patch.

comment:8 Changed 3 years ago by Ilinsekt

Ah. Sorry, I misunderstood you changing the ticket to fixed without posting a reply.

Note: See TracTickets for help on using tickets.