[fix] quote unicode urls
This commit is contained in:
parent
d234939cee
commit
8aee4ebc80
2 changed files with 6 additions and 5 deletions
|
|
@ -4,13 +4,12 @@
|
|||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
import json
|
||||
import urllib
|
||||
from email.utils import formataddr
|
||||
from frappe.website.utils import is_signup_enabled
|
||||
from frappe.utils import get_url, cstr
|
||||
from frappe.utils.email_lib.email_body import get_email
|
||||
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.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):
|
||||
"""set portal link in footer"""
|
||||
|
||||
footer = ""
|
||||
|
||||
if is_signup_enabled():
|
||||
is_valid_recipient = cstr(sent_via.get("email") or sent_via.get("email_id") or
|
||||
sent_via.get("contact_email")) in comm.recipients
|
||||
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 -->
|
||||
<p><a href="%s" target="_blank">View this on our website</a></p>""" % url
|
||||
|
||||
|
|
|
|||
|
|
@ -583,10 +583,13 @@ def 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_url(match):
|
||||
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 re.sub('(href|src){1}([\s]*=[\s]*[\'"]?)((?:http)[^\'">]+)([\'"]?)',
|
||||
_quote_url, html)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue