Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API call with outlinkUrl containing an ampersand does return 0 results #19231

Open
OliverIost opened this issue May 17, 2022 · 3 comments
Open
Labels
Bug For errors / faults / flaws / inconsistencies etc. c: APIs For bugs and features in the Matomo HTTP and plugin APIs. c: Data Integrity & Accuracy

Comments

@OliverIost
Copy link

OliverIost commented May 17, 2022

Expected Behavior

curl "https://www.mydomain.de/matomo/?module=API&idSite=1&format=json&token_auth=XXX&method=Actions.getOutlink&outlinkUrl=https%3A%2F%2Fwww.testdomain.de%2Ftest%2F%3Ftest%3D321%26test2%3D13&period=day&date=2022-04-26"

(and I know that this was called on the day asked) should return something like

[{"label":"/test/?test=321&test2=13","nb_visits":3,"nb_uniq_visitors":3,"nb_hits":3,"sum_time_spent":0,"url":"https://www.testdomain.de/test/?test=321&test2=13"}]%

Current Behavior

Return of
[]%

Possible Solution

Quick fix: I found that the link itself is saved as
https://www.testdomain.de/test/?test=321&test2=13
in the action database but in matomo/plugins/Actions/API.php->getFilterPageDatatableSearch the search comes as
https://www.testdomain.de/test/?test=321&test2=13 so nothing can be found.

Cause I do not know where and what exactly is en/decoded, I only added these lines directly before the last return in
protected function getFilterPageDatatableSearch($callBackParameters, $search, $actionType)
in matomo/plugins/Actions/API.php

if(isset($searchTree[1]) && strpos($searchTree[1],'&')!==false && strpos($searchTree[1],'&')===false) {
$searchTree[1]=str_replace('&','&',$searchTree[1]);
}

Now it works for me.

Your Environment

  • Matomo Version: 4.10
  • PHP Version: 7.4.29
  • Server Operating System: Debian 9.2
@OliverIost OliverIost added the Potential Bug Something that might be a bug, but needs validation and confirmation it can be reproduced. label May 17, 2022
@bx80
Copy link
Contributor

bx80 commented May 17, 2022

Hi @OliverIost, thanks for reporting this and providing a quick fix. I can recreate the issue and confirm that after the quick fix is applied getOutlink API calls with ampersands in the URL are correctly returned. 👍

I'll mark this as a bug so our product team can prioritize it.

(github markdown has encoded the ampersands in the provided code, here is a fixed version for reference)

if (isset($searchTree[1]) &&
    strpos($searchTree[1],'&') !== false &&
    strpos($searchTree[1],'&') === false) {
    $searchTree[1]=str_replace('&','&',$searchTree[1]);
}

@bx80 bx80 added Bug For errors / faults / flaws / inconsistencies etc. Needs priority decision This issue may need to be added to the current milestone by Product Manager and removed Potential Bug Something that might be a bug, but needs validation and confirmation it can be reproduced. labels May 17, 2022
@heurteph-ei
Copy link

Shouldn't the data (in the database) be stored unencoded?
Most of the time, data in DB should be as raw as possible (dates in UTC, urls not encoded, HTML not encoded, etc.)

@bx80
Copy link
Contributor

bx80 commented May 18, 2022

Shouldn't the data (in the database) be stored unencoded?

👍 The root cause of the problem may well be that the URL parameter ampersands are being stored encoded when they should be raw. This is something that should be considered when working on this issue.

@justinvelluppillai justinvelluppillai removed the Needs priority decision This issue may need to be added to the current milestone by Product Manager label May 24, 2022
@mattab mattab added c: Data Integrity & Accuracy c: APIs For bugs and features in the Matomo HTTP and plugin APIs. labels Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc. c: APIs For bugs and features in the Matomo HTTP and plugin APIs. c: Data Integrity & Accuracy
Projects
None yet
Development

No branches or pull requests

5 participants