Test your API with Unicode, emoji and special characters

Your users are called Zoë, Łukasz, Nguyễn, O'Brien and 김민준. Some of them put an emoji in their display name. If the API was only ever tested with "John Smith", at least one of those names will come back mangled, truncated or as a 500.

The strings to send

Keep this list in a JSON file next to your collection:

JSON
[
  { "case": "accents", "value": "Zoë Müller-Lüdenscheidt" },
  { "case": "polish", "value": "Łukasz Żółć" },
  { "case": "vietnamese", "value": "Nguyễn Thị Minh Khai" },
  { "case": "korean", "value": "김민준" },
  { "case": "apostrophe", "value": "O'Brien" },
  { "case": "quotes", "value": "The \"best\" team" },
  { "case": "emoji", "value": "Ana 🚀" },
  { "case": "emoji with modifier", "value": "👩🏽‍💻 dev" },
  { "case": "right to left", "value": "مرحبا بالعالم" },
  { "case": "html", "value": "<b>bold</b> & co" },
  { "case": "backslash", "value": "C:\\temp\\new" },
  { "case": "leading space", "value": "  padded  " }
]

Each one catches a different class of bug: Latin-1 columns, double encoding, SQL or JSON escaping, HTML escaping on input, strlen counting bytes instead of characters, and whitespace trimming nobody agreed on.

Round trip test

A create request that uses the value:

HTTP
POST {{baseUrl}}/customers
Content-Type: application/json

{"displayName": {{valueJson}}, "email": "{{$randomEmail}}"}

{{valueJson}} is the value encoded as a JSON string, so quotes and backslashes in the data don't break the body. Set it in a pre-request script:

JavaScript
pm.variables.set('valueJson', JSON.stringify(pm.iterationData.get('value')));

After the response:

JavaScript
const sent = pm.iterationData.get('value');
const label = pm.iterationData.get('case');

pm.test(`${label}: created`, () => pm.expect(pm.response.code).to.be.oneOf([200, 201]));
pm.test(`${label}: stored exactly`, () => {
  pm.expect(pm.response.json().displayName).to.equal(sent);
});
pm.environment.set('customerId', pm.response.json().id);

Then read it back with a GET and the same "stored exactly" check. The create response sometimes echoes the input while the database stored something else; the second read is the one that tells the truth.

Terminal
requestarium run-collection "Customers API" --folder "Unicode" --env Staging --data unicode.json

Check the content type

JavaScript
pm.test('response declares UTF-8', () => {
  const type = pm.response.headers.get('Content-Type') || '';
  pm.expect(type.toLowerCase()).to.include('application/json');
});

JSON is UTF-8 by definition, so application/json without a charset is fine. For text/plain, text/csv or text/html responses, check that charset=utf-8 is there.

Length limits and emoji

"👩🏽‍💻" looks like one character. It is 4 code points, 7 UTF-16 units and 15 bytes in UTF-8. If the API limits names to 50 "characters", decide which of those it counts and test at the limit with emoji:

JavaScript
const value = '👩🏽‍💻'.repeat(10); // 10 visible, 70 UTF-16 units
pm.variables.set('valueJson', JSON.stringify(value));

A 500 here usually means validation counted one way and the database another.

Search and sort

Store a few of these names, then:

  • Search for zoe and Zoë. Decide whether accent-insensitive search is a feature, and test it either way.
  • Search for O'Brien. An apostrophe in a search query is a classic way to find string-built SQL.
  • Sort by name and check that Łukasz doesn't end up after Zoë if your users expect Polish collation.

See testing search, filtering and sorting for the general approach.

In URLs and headers

Values in the path or query string must be percent-encoded. Try a customer looked up by a name in the query:

HTTP
GET {{baseUrl}}/customers?name=Zo%C3%AB

Header values are a different matter: HTTP headers are not meant for raw non-ASCII text. If your API puts user names into a header (for example Content-Disposition for a download), check that it uses the filename*=UTF-8''… form.