-
Notifications
You must be signed in to change notification settings - Fork 807
Open
Labels
Type/NewFeatureneedTriageThe issue has to be inspected and labeled manuallyThe issue has to be inspected and labeled manuallyuserCategory/Compilation
Description
Description
Description
Ballerina currently lacks a built-in way to escape regex metacharacters when building regex patterns from user/config strings, or to perform literal string replacement without regex matching.
Use Case
When replacing literal strings (e.g., FHIR base URLs) in text, developers need to use re ${baseUrl}.replaceAll(...), but this treats baseUrl as a regex pattern. URLs contain metacharacters like . and ? which cause false-positive matches.
For example:
- If
baseUrl=https://fhir.example.com - The pattern
rehttps://fhir.example.com`` treats.as "match any character" - This would incorrectly match
https://fhirXexampleYcom
Current Limitations
replaceAll()is only available onRegExpobjects and always performs regex matchinglang.regexpmodule doesn't expose anescape()function to escape metacharacters- No
lang.string.replaceAll()method for literal string replacement exists
Proposed Solutions
One of the following would address this:
- Add a
regexp:escape(string)function that escapes regex metacharacters - Add a
string.replaceAll(literal, replacement)method for literal string replacement - Document a recommended pattern for safely building regex from literal strings
Related Discussion
This issue was identified during code review of a FHIR URL rewriting utility:
- PR: [FHIR Connector] Add a general proxy function to forward requests to FHIR server with url rewrite module-ballerinax-health.clients#55
- Discussion: [FHIR Connector] Add a general proxy function to forward requests to FHIR server with url rewrite module-ballerinax-health.clients#55 (comment)
Describe your problem(s)
No response
Describe your solution(s)
No response
Related area
-> Compilation
Related issue(s) (optional)
No response
Suggested label(s) (optional)
No response
Suggested assignee(s) (optional)
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Type/NewFeatureneedTriageThe issue has to be inspected and labeled manuallyThe issue has to be inspected and labeled manuallyuserCategory/Compilation