Skip to content

Implement escape and unescape - #108

Open
FikriMilano wants to merge 1 commit into
ohs-foundation:mainfrom
FikriMilano:escape-unescape
Open

Implement escape and unescape#108
FikriMilano wants to merge 1 commit into
ohs-foundation:mainfrom
FikriMilano:escape-unescape

Conversation

@FikriMilano

@FikriMilano FikriMilano commented Aug 1, 2026

Copy link
Copy Markdown
Member

Implements string functions escape(target) and unescape(target) for the html and json targets (https://hl7.org/fhirpath/en/#escapetarget--string--string).

  • html: escaping turns the special characters &, <, >, " and ' into entities like &amp;, and any character above 127 (accents, symbols, emoji) into a numeric entity like &#233;, as the spec recommends. Unescaping reverses all of these, including numeric entities in decimal and hex.

  • json: escaping makes a string safe to put inside a JSON string, so " becomes \", a backslash becomes \\, and line breaks and similar characters become \n, \t and so on. Unescaping reverses all of these, including \uXXXX codes.

@FikriMilano
FikriMilano requested a review from jingtang10 August 1, 2026 03:28
@FikriMilano FikriMilano self-assigned this Aug 1, 2026
@FikriMilano
FikriMilano requested a review from a team August 1, 2026 03:28
@FikriMilano FikriMilano moved this from Todo to In Progress in FHIR Foundations Aug 1, 2026
Comment thread fhir-path-core/src/commonMain/kotlin/dev/ohs/fhir/fhirpath/functions/Strings.kt Outdated
Comment thread fhir-path-core/src/commonMain/kotlin/dev/ohs/fhir/fhirpath/functions/Strings.kt Outdated
Comment thread fhir-path-core/src/commonMain/kotlin/dev/ohs/fhir/fhirpath/functions/Strings.kt Outdated
Comment thread fhir-path-core/src/commonMain/kotlin/dev/ohs/fhir/fhirpath/functions/Strings.kt Outdated
Comment thread fhir-path/src/commonTest/kotlin/dev/ohs/fhir/fhirpath/EscapeUnescapeTest.kt Outdated
Comment thread fhir-path/src/commonTest/kotlin/dev/ohs/fhir/fhirpath/EscapeUnescapeTest.kt Outdated
Comment thread fhir-path/src/commonTest/kotlin/dev/ohs/fhir/fhirpath/EscapeUnescapeTest.kt Outdated
Comment thread fhir-path/src/commonTest/kotlin/dev/ohs/fhir/fhirpath/EscapeUnescapeTest.kt Outdated
@FikriMilano
FikriMilano requested a review from jingtang10 August 4, 2026 10:37
Comment on lines +406 to +408
} catch (_: Exception) {
return emptyList()
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh sorry i missed this.. what's this for?

@FikriMilano FikriMilano Aug 6, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

malformed input can make unescaping throw, I've added test cases for it.

the spec doesn't say what to do there, so this returns empty instead of crashing

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm interesting. Is there a more detailed exception type you can catch? I really don't like this very broad catch all...

Comment thread fhir-path-core/src/commonMain/kotlin/dev/ohs/fhir/fhirpath/functions/Strings.kt Outdated
Comment thread fhir-path-core/src/commonMain/kotlin/dev/ohs/fhir/fhirpath/functions/Strings.kt Outdated
Comment thread fhir-path-core/src/commonMain/kotlin/dev/ohs/fhir/fhirpath/functions/Strings.kt Outdated
Comment thread fhir-path-core/src/commonMain/kotlin/dev/ohs/fhir/fhirpath/functions/Strings.kt Outdated
Comment thread fhir-path-core/src/commonMain/kotlin/dev/ohs/fhir/fhirpath/functions/Strings.kt Outdated
Comment thread fhir-path-core/src/commonMain/kotlin/dev/ohs/fhir/fhirpath/functions/Strings.kt Outdated
Comment thread fhir-path/src/commonTest/kotlin/dev/ohs/fhir/fhirpath/EscapeUnescapeTest.kt Outdated
Comment thread fhir-path/src/commonTest/kotlin/dev/ohs/fhir/fhirpath/EscapeUnescapeTest.kt Outdated
@FikriMilano
FikriMilano force-pushed the escape-unescape branch 3 times, most recently from 8516161 to 910d215 Compare August 7, 2026 15:58
@FikriMilano

FikriMilano commented Aug 7, 2026

Copy link
Copy Markdown
Member Author

@jingtang10 this is ready.

cleaned some of the implementations, redo the kdoc and comments, tests are more uniform

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants