Predefined XML entities

For help and support with Universal Media Server
Forum rules
Please make sure you follow the Problem Reporting Guidelines before posting if you want a reply
Post Reply
Nadahar
Posts: 1990
Joined: Tue Jun 09, 2015 5:57 pm

Predefined XML entities

Post by Nadahar »

I'm new to UMS, but I allready quite like it. I use just one DLNA client, an Onkyo TX-NR807 - so I only use Audio. I had some problems getting flac to work with the supplied Onkyo (NR717) renderer profile, but I've been able to make my own which is currently playing both mp3 and flac correctly at least. I'll work further on it and post it if I find some relevant place to do that when I consider it "finished".

But, I have one problem that I can't seem to figure out. UMS encodes the text it sends to my Onkyo with HTML character entity (eg & apos ; for ' ), which the Onkyo doesn't understand and just writes out like any other text. The results are hard to read. I don't know what the DLNA standard says about text encoding, but serviio did this correct (although not much more :P) for my Onkyo. Is there anywhere, in the renderer config or elsewhere, where I can specify this encoding? I'm guessing UTF-8 would work fine, since I've seen it being able to display special nordic characters from serviio without problems.

Nadar
Last edited by Nadahar on Tue Jun 16, 2015 3:13 am, edited 1 time in total.
Nadahar
Posts: 1990
Joined: Tue Jun 09, 2015 5:57 pm

Re: HTML character entity

Post by Nadahar »

I downloaded the source, installed Eclipse and Maven and started to trace.... and found the problem (after first checking that texts are being stored correcly in the H2 database): In DNLAResource.java i changed the folloing lines and this fixes the issue as far as I can see:

Code: Select all

		addXMLTagAndAttribute(
			sb,
			"dc:title",
			mediaRenderer.getDcTitle(title, nameSuffix, this)
			//encodeXML(mediaRenderer.getDcTitle(title, nameSuffix, this))
			//TODO: TEMP
		);
		wireshark.append("\"").append(title).append("\"");
		if (firstAudioTrack != null) {
			if (StringUtils.isNotBlank(firstAudioTrack.getAlbum())) {
				addXMLTagAndAttribute(sb, "upnp:album", firstAudioTrack.getAlbum());
				//addXMLTagAndAttribute(sb, "upnp:album", encodeXML(firstAudioTrack.getAlbum()));
			}

			if (StringUtils.isNotBlank(firstAudioTrack.getArtist())) {
				addXMLTagAndAttribute(sb, "upnp:artist",firstAudioTrack.getArtist());
				//addXMLTagAndAttribute(sb, "upnp:artist", encodeXML(firstAudioTrack.getArtist()));
				addXMLTagAndAttribute(sb, "dc:creator", firstAudioTrack.getArtist());
				//addXMLTagAndAttribute(sb, "dc:creator", encodeXML(firstAudioTrack.getArtist()));
			}

			if (StringUtils.isNotBlank(firstAudioTrack.getGenre())) {
				addXMLTagAndAttribute(sb, "upnp:genre", firstAudioTrack.getGenre());
				//addXMLTagAndAttribute(sb, "upnp:genre", encodeXML(firstAudioTrack.getGenre()));
			}

			if (firstAudioTrack.getTrack() > 0) {
				addXMLTagAndAttribute(sb, "upnp:originalTrackNumber", "" + firstAudioTrack.getTrack());
			}
		}
Every Title, Artist, Album etc is ran through encodeXML(). I certainly don't think this is a real "fix", but it's where the problem lies.
Last edited by Nadahar on Tue Jun 16, 2015 3:24 am, edited 1 time in total.
Nadahar
Posts: 1990
Joined: Tue Jun 09, 2015 5:57 pm

Re: HTML character entity

Post by Nadahar »

I'm not sure why I don't get any reply. Can someone at least tell me what I'm doing wrong?

I could submit a bug report, but I'm not sure if it is a bug. I don't have ISO/IEC 29341-3-12:2008 that specifies this communication (if I figured it correctly), and I'm not going to buy the specification just to find out. I'd really appreciate if someone could shed some light on whether UMS or Onkyo is off spec here.
Nadahar
Posts: 1990
Joined: Tue Jun 09, 2015 5:57 pm

Re: Predefined XML entities

Post by Nadahar »

As anyone that knows XML and read this thread will understand, I'm not very familiar with XML :oops:

I finally figured out that these are not HTML character entities, but XML predefined entities and is a part of the XML standard itself. Once I figured that out, things became clearer to me. Everything send to a XML document have to be encoded with these entities per definition.

That led me to look again, and I also found the problem. Forget the code above, everything is fine in DNLAResource.java, the problem is in StringUtil.java. The ampersand (&) is escaped twice, creating all sort of problems and this is definitly a bug. The ampersand obviously has to be escaped first since all the other escapes will include one, and it is, but it's also escaped once again last. That's the problem/bug. I removed the last encoding, and now everything shows correctly at my Onkyo:

Code: Select all

	public static String encodeXML(String s) {
		s = s.replace("&", "&");
		s = s.replace("<", "<");
		s = s.replace(">", ">");
		s = s.replace("\"", """);
		s = s.replace("'", "&apos;");
		//s = s.replace("&", "&");

		return s;
	}
That means that this is definitly a bug, and I should probably submit it somewhere.
User avatar
valib
Developer
Posts: 699
Joined: Fri Feb 08, 2013 3:11 am

Re: Predefined XML entities

Post by valib »

Thanks for that finding. I commited that change.
Nadahar
Posts: 1990
Joined: Tue Jun 09, 2015 5:57 pm

Re: Predefined XML entities

Post by Nadahar »

I already did a fork and was preparing a pull request, but that's not needed anymore now. I've have a couple of other minor things I will do a pull request for though, but I'm still working on that.
Post Reply