Warning: Can't synchronize with repository "(default)" (No changeset 96d22ec3fa3ef6de3ea8dc0d7d398adc9aa071cf in the repository). Look in the Trac log for more information.

Ticket #85 (closed task: fixed)

Opened 5 years ago

Last modified 5 years ago

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

encodehtmlentitiesinsms.patch (446 bytes) - added by benito 5 years ago.
encode three more characters in sms-body to html
encodehtmlentitiesinsms.2.patch (446 bytes) - added by benito 5 years ago.
encode three more characters in sms-body to html

Change History

Changed 5 years ago by benito

encode three more characters in sms-body to html

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

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.

comment:3 Changed 5 years ago by mickey

  • Owner changed from mickey to jluebbe

Jan?

comment:4 Changed 5 years ago by mickey

  • Type changed from defect to task
  • Milestone set to milestone4

comment:5 Changed 5 years ago by Jan Lübbe <jluebbe@…>

  • Status changed from new to closed
  • Resolution set to fixed

This is now fixed and tested. Thanks for your bug report.

Note: See TracTickets for help on using tickets.