witty-holiday-65473
02/04/2024, 1:49 PMregex.go to support multi-byte delimiters by slightly refactoring the delimiterIndices to process []rune (string cast to []rune) and rune (byte cast to rune) for the pattern, delimiterStart, and delimiterEnd parameters respectively.
• Updated ory/ladon's regex.go CompileRegex to send delimiterIndicies parameters cast properly and gently refactored the internal for loop to support the update from string to []rune.
• Why? Processing the string as a []rune eliminates the importance of the delimiter byte length. Each "character" of the string is processed as a distinct "character". Since these characters can be multi-byte, using []rune eliminates the need to care. This means that a pattern can look like this:
◦ urn:foo:«(?<type>\w+):(?<id>(?<!hax:)\w+)» or urn:foo:<<(?<type>\w+):(?<id>(?<!hax:)\w+)>> and inputs urn:foo:person:user1 or urn:foo:user:user2 would match but urn:foo:haxor:user3 would not match.
• But... Why? My use-case requires negative lookbehind to make my oathkeeper rules not make me want to cry. Since oathkeeper uses dlclark/regexp2, lookbehind (and friends) are already supported out-of-the-box. The issue is that within oathkeeper (read: ladon) there is a bug that occurs when it attempts to parse a rule with (?< or (?> included in the pattern; as would be the case for positive lookbehind, negative lookbehind, and possessive matches. My modification fixes this.