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

Created on 12 Nov 2015  Â·  10Comments  Â·  Source: faker-ruby/faker

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.

Most helpful comment

@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.

All 10 comments

+1

+1

+1

(runs over to CircleCI to hit rebuild)

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

+1 still nothing on this?

@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.

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.

+1 on this

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

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. :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mkeiser82 picture mkeiser82  Â·  3Comments

huyderman picture huyderman  Â·  4Comments

benpolinsky picture benpolinsky  Â·  5Comments

neutralino1 picture neutralino1  Â·  3Comments

zyrthofar picture zyrthofar  Â·  6Comments