ampproject / ampproject/amp-toolbox-php

ampersand sign converted into unicode when added to analytics config.

Open
#529 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
74
Forks
25
Avg merge
1d 15h
Merged PRs (30d)
3

Description

**Bug Description**

A user reported on support forums that the `&` is being converted to Unicode character `\u0026` when being added to the analytics config.

After disabling optimizer it did output correctly
`add_filter( 'amp_enable_optimizer', '__return_false' );`

**Steps to reproduce**
You can reproduce using the AMP plugin for WordPress, steps assuming that you have WordPress site with AMP plugin installed

Step 1 : Login as Admin
Step 2: Goto AMP->Settings->Analytics
Step 3: Enter the type as "test" (you can add anything as type was unknow from support topics)
Step 4: add JSON config as below

```json
{
"requests": {
"custom_params": "cp1=test&cp2=test"
},
"vars": {
"env": "-preproduction"
},
"triggers": {
"trackConsent": {
"on": "visible",
"request": "impression"
}
}
}
```

**Expected Output**
Same output as entered in config.

**Current Behaviour**

```json
{
"requests": {
"custom_params": "cp1=test\u0026cp2=test"
},
"vars": {
"env": "-preproduction"
},
"triggers": {
"trackConsent": {
"on": "visible",
"request": "impression"
}
}
}
```

**Screenshot**
| Input | Output |
| ------------- | ------------- |
| ![image](https://user-images.githubusercontent.com/1132541/184157996-86013f4a-b612-4e99-a404-071d498b236c.png) | ![image](https://user-images.githubusercontent.com/1132541/184158248-9eb53ff4-fbc1-4912-a365-51fa2a3929d8.png) |

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the analytics configuration steps with the AMP optimizer enabled, then trace how the JSON config is processed and emitted. Confirm the fix by checking that the ampersand in custom_params remains unchanged in the generated output.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.