我在notifier_test.rb中有一个测试,其中Notifier是我的邮件发送器类。
mail = Notifier.registered_client(client.firstname, client.emailaddress)
assert_match I18n.t('notifier.registered_client.email_body'), mail.body.encoded, 'Email contents should be correct'
这个测试在Rails 3.2.8之前是通过的,但现在测试失败了,错误信息如下:
NotifierTest
FAIL (0:00:07.963) should create registration email in English
Email contents should be correct.
Expected /In\ order\ to\ activate\ your\ company's\ registration\ you\ must\ click\ on\ the\ following\ link:/
to match
"\nDear First Name, thanks for registering.\n\nIn order to activate your company\'s registration you must click on the following link:\n\nhttp://localhost:3000/en/clients/activate?email=english%40email.com&key=7b6e6ed1-ac03-4d95-a0d5-6f2541092dd0\n".
错误似乎是因为我的邮件文本包含一个撇号,而
mail.body.encoded
现在返回的是 \'
,这是由于补丁引起的:CVE-2012-3464 Ruby on Rails 中的潜在 XSS 漏洞,具体描述请见此处。
最聪明的方法是以相同方式对 I18n.t 返回的字符串进行编码,或从我的邮件对象中获取不含撇号的文本。