faker icon indicating copy to clipboard operation
faker copied to clipboard

Strings generated with characters that are HTML-escaped cause test failures

Open testflyjets opened this issue 11 years ago • 10 comments

In testing the dynamic content of an HTML email I discovered that some of the names generated by Faker::Name.last_name contained apostrophes, such as "O'Kon".

When this string was rendered in the email template it was rendered with the apostrophe escaped to an HTML entity and this caused the regex-based matcher to fail.

It would be great to be able to generate "HTML-safe" strings from Faker that don't contain any characters that will be HTML-escaped by template renderers.

testflyjets avatar Nov 12 '15 00:11 testflyjets

+1

castrolem avatar Nov 30 '15 17:11 castrolem

+1

mattpickle avatar Dec 03 '15 17:12 mattpickle

+1

(runs over to CircleCI to hit rebuild)

seebq avatar May 27 '16 17:05 seebq

+1 (also just hit rebuild in Travis for this)

pleary avatar May 27 '16 17:05 pleary

+1 still nothing on this?

JoeWoodward avatar Jul 20 '16 10:07 JoeWoodward

@JoeWoodward PRs are always welcome. ;)

Alternatively, one can use locales to override the default selection of names to avoid ones that cause problems in particular scenarios.

stympy avatar Jul 20 '16 14:07 stympy

OK, I've overriden the locale for now. I'll push a PR when I get a chance

On 20 Jul 2016, at 9:50 pm, Benjamin Curtis [email protected] wrote:

@JoeWoodward PRs are always accepted. ;)

Alternatively, one can use locales to override the default selection of names to avoid ones that cause problems in particular scenarios.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

JoeWoodward avatar Jul 20 '16 15:07 JoeWoodward

+1 on this

jschorr avatar Aug 26 '16 14:08 jschorr

For the case of the names there's already a PR open https://github.com/stympy/faker/pull/716

fidalgo avatar Dec 07 '17 12:12 fidalgo

I have thought about this a bit more, and I don't think solving this in Faker is the way to go. Instead, I would suggest three potential ways to deal with this:

  1. As I mentioned previously, if you want to ensure that you don't get a name that has characters that could be escaped, you can override the locale.
  2. In your test that uses a Faker name, loop until you get a name back from Faker that works for your scenario.
  3. Update the match in your test to escape the name, just as your template renderer would.

I recommend option 3. Apostrophes happen in real life, so you might as well make your test resilient enough to handle real-world scenarios. Of course, you're welcome to ignore my recommendation -- I'm just some random guy on the internet. :)

stympy avatar Dec 07 '17 16:12 stympy