Description
A new string function MASK has been added:
MASK(source,options)
|
A simple scalar function for character masking.
Source is a string and options is an object listing the following possible options:
mask
the mask string to use (default: "********")
hole
the string of characters used to indicate holes in the mask (default: space)
inject
the string of characters present in the mask that are inserted rather than overlaying the source. (default:none)
length
missing / "source". Output is the length of either the mask (if missing or not "source") or the source. If mask, the overall length is the anchor (see below) plus the mask. If source, the overall length is the source truncating the mask as needed.
anchor
"start"/"end"/<regex>/number
- "start" mask is anchored at the start of the source and applied towards the end.
- "end" mask is anchored at the end of the source and is applied from end towards start.
- <regex> pattern to match to find anchor point. First match is used. Mask applied towards end. To match "start" or "end" patterns such as "[s]tart"/"[e]nd" can be used.
- number character position to anchor the mask. Negative are relative to the end of the source. With positive values mask is applied towards end; with negative values, towards start.
If an anchor places the mask outside the boundaries of the source string, the source string is returned unchanged.
Examples:
Default mask, custom mask, custom mask demonstrating holes:
select mask('SomeTextToMask'),mask('SomeTextToMask',{"mask":"++++"}),mask('SomeTextToMask',{"mask":"++++ ++++"}); |
"results": [ |
{
|
"$1": "********", |
"$2": "++++", |
"$3": "++++Text++++" |
}
|
Mask with character injection:
select mask('1234abcd5678efgh',{"mask":"****-****-****-####","hole":"#","inject":"-"}); |
"results": [ |
{
|
"$1": "****-****-****-efgh" |
}
|
Mask anchored to the end of the source with the output length determined by the source:
select mask('1234abcd5678efgh',{"mask":"****","anchor":"end","length":"source"}); |
"results": [ |
{
|
"$1": "1234abcd5678****" |
}
|
Mask anchored at the pattern "d5":
select mask('1234abcd5678efgh',{"mask":"****","anchor":"d5"}); |
"results": [ |
{
|
"$1": "1234abc****" |
}
|
Mask with its end anchored 2 characters from the end of the source:
select mask('1234abcd5678efgh',{"mask":"****","anchor":-2,"length":"source"}) |
"results": [ |
{
|
"$1": "1234abcd56****gh" |
}
|
Mask anchored at the 14th character with length from the source:
select mask('1234abcd5678efgh',{"mask":"****","anchor":14,"length":"source"}); |
"results": [ |
{
|
"$1": "1234abcd5678ef**" |
}
|
Attachments
Issue Links
- is triggered by
-
MB-17196 Data masking certain data keys using N1QL scalar functions and SDK APIs
- Resolved
- links to