phpCacheAdmin icon indicating copy to clipboard operation
phpCacheAdmin copied to clipboard

Bug: Incorrect Display of Escaped JSON Strings in Redis Value Viewer (Breaks HTML Rendering in JSON Objects)

Open bzcomputers opened this issue 1 year ago • 4 comments

What version of phpCacheAdmin are you using?

2.3.1

Cache system and version

No response

Extension or client and version

No response

PHP Version

8.4.14

Operating System

AlmaLinux 8

Describe the issue

phpCacheAdmin’s value viewer misrepresents valid JSON strings containing escaped HTML. It shows <\/a> and \" as literal characters instead of rendering the decoded, clean HTML that json_decode() produces in PHP.

This creates false appearance of data corruption, even though:

  1. The Redis data is valid JSON
  2. json_decode() in PHP works perfectly
  3. The application renders correct HTML

The issue is purely visual in the UI and does not affect data integrity.

Steps to Reproduce:

  1. Store a JSON string in Redis containing HTML with closing tags (e.g., </a>) and double quotes.
  2. View the key in phpCacheAdmin.
  3. Observe broken display: <\/a> and \" remain escaped.

Expected Behavior: The viewer should either: Show raw escaped JSON (like redis-cli) Or decode and display clean HTML (like after json_decode())

Actual Behavior: Partial unescaping breaks the preview: <\/a> remains as <\/a> (not converted to </a>) \" remains as \" (not converted to ")

Result: HTML appears broken and unreadable.

bzcomputers avatar Nov 12 '25 17:11 bzcomputers

Not sure if you were done with the fix or not, but I did try the updated scripts.js and had the same issues. Figure I'd let you know before a new release cycle.

Issue Example - Seen in phpCacheAdmin:

{
    "html": "
\"Track
Empress<\/a>
In Service: 1990<\/span><\/li>",
    "total_count": 1,
    "upcoming_count": 0
}

Actual stored in redis:

"{\"html\":\"<li><a href=\\\"\\/ship-tracker\\/cordelia-cruises\\/empress\\/\\\" title=\\\"Empress Cruise Ship Tracker\\\"><img src=\\\"\\/images\\/ships\\/cordelia-cruises\\/empress.webp\\\" alt=\\\"Track Empress in real-time\\\" width=\\\"500\\\" height=\\\"250\\\" loading=\\\"lazy\\\"><br \\/>Empress<\\/a><span class=\\\"ship-category-class-inservice\\\"><br \\/>In Service: 1990<\\/span><\\/li>\",\"total_count\":1,\"upcoming_count\":0}"

bzcomputers avatar Nov 13 '25 04:11 bzcomputers

This should be visual bug with custom json highlighter.

Here https://github.com/RobiNN1/phpCacheAdmin/blob/master/src/Value.php#L66C27-L66C51 remove class="json-code" to disable it and let me know if it fixed it.

RobiNN1 avatar Nov 13 '25 08:11 RobiNN1

That definitely fixed it. Just no more pretty highlighting. Thanks.

bzcomputers avatar Nov 13 '25 13:11 bzcomputers

I'll remove it. There are probably more issues and I don't want to add a whole js library just for JSON highlighting.

RobiNN1 avatar Nov 13 '25 13:11 RobiNN1