Skip to content

Commit 4e4b5b9

Browse files
authored
doc: user guide: sexpr and invalid escaped char (#296)
Closes #295
1 parent 41c7e93 commit 4e4b5b9

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

CHANGELOG.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ A release with known breaking changes is marked with:
3737
* docs
3838
** Turf API diff reports for now
3939
{issue}132[#132] ({lread})
40+
** Rewrite-clj can rewrite invalid escaped chars but will throw on `sexpr`
41+
{issue}295[#295] ({lread})
4042

4143
=== v1.1.47 - 2023-03-25 [[v1.1.47]]
4244

doc/01-user-guide.adoc

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,25 @@ If you try to `sexpr` a node with invalid metadata you will get an exception:
834834
;; => "Metadata must be a map, keyword, symbol or string"
835835
----
836836

837+
[[invalid-escaped-characters]]
838+
=== Invalid Escaped Characters
839+
840+
In Clojure, some escaped characters in strings are not valid.
841+
Rewrite-clj doesn't much care, it will happily read and write strings with invalid escaped chars.
842+
If you `sexpr` a node with such a string, you will get an exception:
843+
844+
//#:test-doc-blocks {:reader-cond :clj}
845+
[source,clojure]
846+
----
847+
(try
848+
(-> "\"some string is wrong here \\x\""
849+
z/of-string
850+
z/sexpr)
851+
(catch Throwable e
852+
(.getMessage e)))
853+
;; => "Unsupported escape character: \\x."
854+
----
855+
837856
[#sexpr-nuances]
838857
== Sexpr Nuances
839858

@@ -905,8 +924,8 @@ Both the zip and node APIs include `sexpr-able?` to check if sexpr is supported
905924
====
906925
`sexpr-able?` only looks at the current node element type. This means that `sexpr` will still throw when:
907926
908-
1. called on a node with an element type that is `sepxr-able?` but, for whatever reason, has a child node that fails to `sexpr`, see link:#unbalanced-maps[unbalanced maps] and link:#invalid-metadata[invalid metadata].
909-
2. called directly on an link:#unbalanced-maps[unbalanced maps] or node with link:#invalid-metadata[invalid metadata].
927+
1. called on a node with an element type that is `sepxr-able?` but, for whatever reason, has a child node that fails to `sexpr`, see link:#unbalanced-maps[unbalanced maps], link:#invalid-metadata[invalid metadata], and link:#invalid-escaped-characters[invalid escaped characters].
928+
2. called directly on an link:#unbalanced-maps[unbalanced maps] or node with link:#invalid-metadata[invalid metadata] or node with link:#invalid-escaped-characters[invalid escaped characters].
910929
====
911930

912931
[source, clojure]

0 commit comments

Comments
 (0)