From e8f1c4bd48350789300c5f87c5ea21ea4256cf6f Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Wed, 26 Feb 2025 02:35:09 +0100 Subject: [PATCH] Add support for hexadecimal HTML escape codes --- CHANGELOG.md | 1 + src/utility/html.cpp | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07fbd98b..d48d84db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # ncmpcpp-0.10.2 (2025-??-??) * Update lyrics fetchers. +* Add support for hexadecimal HTML escape codes. # ncmpcpp-0.10.1 (2024-10-24) * Fix compilation with `libc++`. diff --git a/src/utility/html.cpp b/src/utility/html.cpp index 9ef71bec..72553845 100644 --- a/src/utility/html.cpp +++ b/src/utility/html.cpp @@ -20,16 +20,29 @@ #include #include +#include #include "utility/html.h" std::string unescapeHtmlUtf8(const std::string &data) { + int base; + size_t offset; std::string result; for (size_t i = 0, j; i < data.length(); ++i) { if (data[i] == '&' && data[i+1] == '#' && (j = data.find(';', i)) != std::string::npos) { - int n = atoi(&data.c_str()[i+2]); + if (data[i+2] == 'x') + { + offset = 3; + base = 16; + } + else + { + offset = 2; + base = 10; + } + int n = strtol(&data.c_str()[i+offset], nullptr, base); if (n >= 0x800) { result += (0xe0 | ((n >> 12) & 0x0f));