Scrobbler 2.0 error: Extra content at the end of the document #100
-
Error doesn't come directly from the scrobbler plugin, but rather from
No idea what's going on here since the XML seems to be perfectly valid. Any ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
libxml doesn't care about newlines at the end. For me it looks like an off-by-one error. This patch makes the parsing work. diff --git a/src/scrobbler2/scrobbler_xml_parsing.cc b/src/scrobbler2/scrobbler_xml_parsing.cc
index 3320a32b0..8e869c41f 100644
--- a/src/scrobbler2/scrobbler_xml_parsing.cc
+++ b/src/scrobbler2/scrobbler_xml_parsing.cc
@@ -10,7 +10,7 @@ static gboolean prepare_data () {
received_data[received_data_size] = '\0';
AUDDBG("Data received from last.fm:\n%s\n%%%%End of data%%%%\n", received_data);
- doc = xmlReadMemory(received_data, received_data_size+1, nullptr, nullptr, 0);
+ doc = xmlReadMemory(received_data, received_data_size, nullptr, nullptr, 0);
received_data_size = 0;
if (doc == nullptr) {
AUDDBG("Document not parsed successfully.\n"); I have tested it with this example code. Notice the additional #include <stdio.h>
#include <string.h>
#include <libxml/parser.h>
/* Compile with gcc -Wall -o lastfm_test lastfm_test.c $(pkg-config --cflags --libs libxml-2.0) */
int main()
{
const char * received_data =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<lfm status=\"ok\">\n"
" <token>Lorem-ipsum-dolor-sit-amet</token>\n"
"</lfm>\n\n\n";
size_t received_data_size = strlen(received_data);
printf("strlen(received_data): %zu\n", received_data_size);
xmlDocPtr doc = xmlReadMemory(received_data, received_data_size /* + 1 */, NULL, NULL, 0);
if (!doc)
{
printf("Parsing failed\n");
return -1;
}
xmlFreeDoc(doc);
printf("Parsing successful\n");
return 0;
} @jlindgren90: Is this fix valid for you? I wonder why/how this has worked in the past. Edit: Tested on Ubuntu 20.04 with an older libxml2 version (2.9.10). Here |
Beta Was this translation helpful? Give feedback.
-
Fixed with audacious-media-player/audacious-plugins@5103ba0, thanks for reporting. |
Beta Was this translation helpful? Give feedback.
Fixed with audacious-media-player/audacious-plugins@5103ba0, thanks for reporting.