My current employment uses Spring Cloud Contracts to write contracts between microservices. And while they are a good step to guarantee things work between apps, the way it is used today makes it very easy to pass bad data. As an IT person, I hate those "fancy" because when pasted into code or as a character to define text, they don't work. And with some fonts it can be really hard to see any difference.
Spring Cloud Contracts comes with a DSL for creating these contracts but sadly created a helper method called `anyNonEmptyString`. The regex is something like `[\S\s]+`. And while that gives you the flexibility to send anything you want, it also allows you to send anything you want! At any length! Can you imagine what a 2 billion character string would do to your program? I also don't like the open-ended length a string can be using `anyNonEmptyString`. Some sane defaults should be required in your contracts.
This allows for characters that look like ASCII characters but aren't to get into your data stream. If you're expecting a comma-delimited list but the comma is "،" your program wouldn't work correctly. I've personally come across a case where loading data into a system didn't work because a "fancy" quote was in the stream of characters. I turn off this feature whereever I can. Most Office apps do this and MacOS.
- Reasons to NOT use `anyNonEmptyString()`
- unexpected errors or degrade in performance for your app
- passing it along to another service potentially masking the true source
Like most problems, the sooner you can identify and fix issues the better. And what better place than your service contracts?
Character class | Abbreviation | Description |
---|---|---|
\p{Letter} | \p{L} | Includes a letter from any language |
\p{Number} | \p{N} | Includes any numeric character in any language |