From 282e509d1eb19969c0775e948dc9d0e58ecd1fef Mon Sep 17 00:00:00 2001 From: liuzicheng1987 Date: Sat, 4 Nov 2023 12:41:27 +0100 Subject: [PATCH] Documented rfl::Pattern --- docs/validating_numbers.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 docs/validating_numbers.md diff --git a/docs/validating_numbers.md b/docs/validating_numbers.md new file mode 100644 index 00000000..32d605c8 --- /dev/null +++ b/docs/validating_numbers.md @@ -0,0 +1,19 @@ +# `rfl::Pattern` + +`rfl::Pattern` can be used to verify that a string fits a particular pattern, the latter of which is expressed as a regular expression. + +A common problem for backend applications or data pipelines is SQL injection. `rfl::Pattern` can be used to limit the allowed characters +users are able to pass. For instance, for table names, we might only allow uppercase characters and +underscores: + +```cpp +using TableName = rfl::Pattern; +``` + +Because the regex is encoded at compile time, you can be certain that whenever you use the type `TableName`, the string contained +therein will fit the pattern. This is a very strong safeguard against SQL injection. + +Note that use also have to give a reasonable name to the pattern. That is, because reflect-cpp emphasizes readable error messages and regex patterns can be somewhat hard to decipher at times. + +To retrieve the underlying string, you can use the `.value()` method. +