Browse Source

[fix] quote unicode urls

version-14
Anand Doshi 10 years ago
parent
commit
8aee4ebc80
2 changed files with 6 additions and 5 deletions
  1. +2
    -4
      frappe/core/doctype/communication/communication.py
  2. +4
    -1
      frappe/utils/data.py

+ 2
- 4
frappe/core/doctype/communication/communication.py View File

@@ -4,13 +4,12 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
import json import json
import urllib
from email.utils import formataddr from email.utils import formataddr
from frappe.website.utils import is_signup_enabled from frappe.website.utils import is_signup_enabled
from frappe.utils import get_url, cstr from frappe.utils import get_url, cstr
from frappe.utils.email_lib.email_body import get_email from frappe.utils.email_lib.email_body import get_email
from frappe.utils.email_lib.smtp import send from frappe.utils.email_lib.smtp import send
from frappe.utils import scrub_urls, cint
from frappe.utils import scrub_urls, cint, quoted
from frappe import _ from frappe import _


from frappe.model.document import Document from frappe.model.document import Document
@@ -167,14 +166,13 @@ def attach_print(mail, sent_via, print_html, print_format):


def set_portal_link(sent_via, comm): def set_portal_link(sent_via, comm):
"""set portal link in footer""" """set portal link in footer"""

footer = "" footer = ""


if is_signup_enabled(): if is_signup_enabled():
is_valid_recipient = cstr(sent_via.get("email") or sent_via.get("email_id") or is_valid_recipient = cstr(sent_via.get("email") or sent_via.get("email_id") or
sent_via.get("contact_email")) in comm.recipients sent_via.get("contact_email")) in comm.recipients
if is_valid_recipient: if is_valid_recipient:
url = "%s/%s/%s" % (get_url(), urllib.quote(sent_via.doctype), urllib.quote(sent_via.name))
url = quoted("%s/%s/%s" % (get_url(), sent_via.doctype, sent_via.name))
footer = """<!-- Portal Link --> footer = """<!-- Portal Link -->
<p><a href="%s" target="_blank">View this on our website</a></p>""" % url <p><a href="%s" target="_blank">View this on our website</a></p>""" % url




+ 4
- 1
frappe/utils/data.py View File

@@ -583,10 +583,13 @@ def expand_relative_urls(html):


return re.sub('(href|src){1}([\s]*=[\s]*[\'"]?)((?!http)[^\'" >]+)([\'"]?)', _expand_relative_urls, html) return re.sub('(href|src){1}([\s]*=[\s]*[\'"]?)((?!http)[^\'" >]+)([\'"]?)', _expand_relative_urls, html)


def quoted(url):
return cstr(urllib.quote(encode(url), safe=b"~@#$&()*!+=:;,.?/'"))

def quote_urls(html): def quote_urls(html):
def _quote_url(match): def _quote_url(match):
groups = list(match.groups()) groups = list(match.groups())
groups[2] = urllib.quote(groups[2].encode("utf-8"), safe=b"~@#$&()*!+=:;,.?/'").decode("utf-8")
groups[2] = quoted(groups[2])
return "".join(groups) return "".join(groups)
return re.sub('(href|src){1}([\s]*=[\s]*[\'"]?)((?:http)[^\'">]+)([\'"]?)', return re.sub('(href|src){1}([\s]*=[\s]*[\'"]?)((?:http)[^\'">]+)([\'"]?)',
_quote_url, html) _quote_url, html)


Loading…
Cancel
Save