Jump to content
Teo

Script filter stumbles on special characters in xml.

Recommended Posts

Hi Alfred users.

 

I'm not completely sure this is a bug so I'm posting it here first. 

 

I have written a script that outputs xml which some times contains special characters.

It seems that the xml interpreter in Alfred does not know what to do with those and aborts the whole script filter without any error in the debug log. A simple example would be:

 

<?xml version="1.0" encoding="UTF-8"?><items><item arg="http://www.glossed.it/highlights" valid="YES" type="file"><title>title Ð</title><subtitle>test</subtitle><icon type="fileicon"></icon></item></items>

 

I've coloured the offending character red. Without it the script filter works fine.

 

Am I correct in thinking this is a bug in Alfred?

 

Best regards,

Teo

Share this post


Link to post

No, this isn't a bug. Replace "Đ" with "Đ", the XML entity form of that character.

 

I assume you generated this output manually (i.e. you didn't use a workflow helper library). You might consider using a workflow helper library that handles the XML generation and encoding for you ;)

Share this post


Link to post

It will also work without using XML entities, but you have to actually encode the text to UTF-8 (which is what you've declared as the charset in the XML header).

 

Nevertheless, as Tyler says, you're better off using a library to generate your XML for you. It's not entirely straightforward.

Edited by deanishe

Share this post


Link to post

CDATA doesn't help if the encoding is wrong (Alfred won't display the result), which it is here because the posted XML is perfectly valid if properly encoded as UTF-8.

Share this post


Link to post

Thank you everyone for your suggestions.

 

Not knowing much about the xml I just ran the output through a few online xml verifier tools which all came back OK.

 

I will have a deeper look now that I know the fault is on my side of things.

 

:)

Teo

Share this post


Link to post

Chances are your browser is correcting the encoding when you paste the text into the form field (browsers are very good at that).

The best thing to do it what Tyler advised and use an XML generation library (or one of the workflow helper libraries) to produce your XML.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...