我们的应用程序要求将电子邮件发送到格式化的地址以进行跟踪,发送到邮件客户端所需的格式如下:
<a href="mailto\:David Contact<{contactId=2} {userId=2} {pitchingInitiativeId=9}@mail.com>" target="_blank">
在我的模板中,我像这样格式化 href 字符串...
mailto:{{contact.name}}<{contactId={{contact.contactId}}} {userId={{userId}}} {pitchingInitiativeId={{pitchingInitiativeId}}}@propelmymail.com>
这会产生一个格式如下的 mailto 链接:
mailto:Reporter%3C%7BcontactId=1%7D%20%7BuserId=7%7D%20%7BpitchingInitiativeId=21%7D@propelmymail.com%3E
这显然是不正确的。如何修复此问题以使 mailto 链接的格式正确?我相信人们普遍认为 URL 中的特殊字符是危险的,但在本例中这是要求。我想我只是从来没有学会如何逃离它们或将它们标记为安全。
最佳答案
Which Characters Are Allowed in URLs?
Not all special characters will cause an issue in your URLs. There are many safe characters. Other non-safe characters risk poor readability, breaking some browsers and causing issues for crawlers.
Safe characters Standard characters:
0 1 2 3 4 5 6 7 8 9 a b c d e f g h I j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Special characters:
$ – _ . + ! * ‘ ( ) ,
来自:https://www.abramillar.com/2018/01/15/special-characters-short-words-urls/
还请看一下 - Uniform Resource Identifier (URI): Generic Syntax
<小时/>根据设计,您不应该被允许解析其他字符。
我的建议是将您需要跟踪的任何内容放入标题或电子邮件正文中。
关于javascript - Angular 模板中的 url 字符编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49768120/