What is the "'" in "can't be blank"? LiveView

Hi,

I am using factories as my test data and one of the fields in my factory uses Faker.Person.last_name() to generate the last names. But I noticed that my test fails whenever the last name is in a format like these “O’Henry”, “D’Souza”.

In my test file I have this,
render_change() =~ "can't be blank"

The error returned is as follows

Left: D'Souza
Right: D'Souza

Any idea on how we could possibly resolve this?

HTML-escaped '. ' is ASCII 39 and &#<decimal unicode codepoint>; is used to escape dangerous HTML characters.

Thank you, it makes sense now but is there any way that we could avoid 39 from replacing apostrophe?

it’s part of making correct HTML, why would you avoid doing it?

I resolved it by aligning my expected response to consist of “&#39

1 Like

HTML entities are used to avoid typing symbols and to not break any engine that might parse your document, since some characters are reserved to HTML, one of them being the single quotes ', which can be typed as &apos; or even more portable &#39;.

mozilla docs

1 Like

Many don’t know that, but Tim Berners Lee even coded the first version of the web in html-entity-flavored-C

See a recording of him coding the web here

Objective-C used such flavour of escape entities? Interesting.

In a few projects if mine I’ve added an html_escaped/1 helper function to my ConnCase, which delegates to Plug.HTML.html_escape/1.

This way you can write your tests like this:

assert body =~ html_escaped("can't be blank")
8 Likes