Ticket #85 (closed task: fixed)
encode html-entities in SMS-body
| Reported by: | benito | Owned by: | jluebbe |
|---|---|---|---|
| Priority: | minor | Milestone: | milestone4 |
| Component: | zhone/general | Version: | |
| Keywords: | Cc: | openmoko@… |
Description
Currently, only '\n' is encoded into '<br>'. So if a message contains an ampersand ('&') it will not be displayed correctly but cut off at that character as the html-engine probably waits for the closing semicolon.
I attached a rather ugly small patch that additionally encodes '&', '<' and '>'. But this probably should be fixed in a more general way. (I'm not python-literate enough to do that on my own.)
Attachments
Change History
Changed 5 years ago by benito
- Attachment encodehtmlentitiesinsms.patch added
comment:1 Changed 5 years ago by benito
Ahem... patch revised (don't encode the '<br>' we just inserted...)
Changed 5 years ago by benito
- Attachment encodehtmlentitiesinsms.2.patch added
encode three more characters in sms-body to html
comment:2 Changed 5 years ago by pjz
Your patch works as well as using existing libraries, really, given the extra overhead of having to import said library in the first place. This would work:
import xml.sax.saxutils
# <, &, > are converted by default. Add other # desired conversions here: extras = { "\n": "<br>" } xml.sax.saxutils.escape(self.current[self.selected][3], extras)
or more simply: import xml.sax.saxutils
xml.sax.saxutils.escape(self.current[self.selected][3], { "\n": "<br>" })
cgi.escape almost works for you but doesn't let you define custom conversions so easily, so you'd have to still do the .replace() thing with \n anyway.
So take your pick.

encode three more characters in sms-body to html