<div class="__aliyun_email_body_block"><div style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun"><div style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><div style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><div class="alimail-quote"><div style="clear: both;">------------------------------------------------------------------</div><div style="clear: both;">From:jinser <aimer@purejs.icu></div><div style="clear: both;">Send Time:2025 Sep. 17 (Wed.) 16:34</div><div style="clear: both;">To:"沈达"<da@liii.pro></div><div style="clear: both;">Subject:Fwd: [PATCH] Fix R7RS newline escaping in string serialization</div><div style="clear: both;"><br ></div><div ></div><br ><div class="gmail_quote gmail_quote_container"><div class="gmail_attr">---------- Forwarded message ---------<br >发件人: <strong class="gmail_sendername">Jinser Kafka</strong> <span ><aimer@purejs.icu></span><br >Date: 2025年9月17日周三 14:42<br >Subject: [PATCH] Fix R7RS newline escaping in string serialization<br >To: <<a href="mailto:997460364@qq.com" target="_blank">997460364@qq.com</a>><br ></div><br ><br >In R7RS mode, newlines in strings should be escaped as \n to ensure<br >
proper serialization and readback compatibility. This change:<br ><br >
- Makes slashify_table escape newlines when WITH_R7RS is defined<br >
- Adds newline case to slashify_string_to_port for proper \n output<br ><br >
This fixes issues where strings containing newlines would not serialize<br >
correctly in R7RS mode, breaking the round-trip property of write/read.<br >
---<br >
s7.c | 6 ++++++<br >
1 file changed, 6 insertions(+)<br ><br >
diff --git a/s7.c b/s7.c<br >
index 273f6d1..4534a01 100644<br >
--- a/s7.c<br >
+++ b/s7.c<br >
@@ -15584,7 +15584,12 @@ static void init_ctables(void)<br >
/* for (int32_t i = 127; i < 160; i++) slashify_table[i] = true; */ /* 6-Apr-24 for utf-8, but this has no effect on s7test?? */<br >
slashify_table[(uint8_t)'\\'] = true;<br >
slashify_table[(uint8_t)'"'] = true;<br >
+#if WITH_R7RS<br >
+ /* In R7RS mode, newlines should be escaped to ensure proper serialization */<br >
+ slashify_table[(uint8_t)'\n'] = true;<br >
+#else<br >
slashify_table[(uint8_t)'\n'] = false;<br >
+#endif<br ><br >
for (int32_t i = 0; i < CTABLE_SIZE; i++)<br >
symbol_slashify_table[i] = ((slashify_table[i]) || (!char_ok_in_a_name[i])); /* force use of (symbol ...) for cases like '(ab) as symbol */<br >
@@ -33935,6 +33940,7 @@ static void slashify_string_to_port(s7_scheme *sc, s7_pointer port, const char *<br >
case '\'': port_write_character(port)(sc, '\'', port); break;<br >
case '\t': port_write_character(port)(sc, 't', port); break;<br >
case '\r': port_write_character(port)(sc, 'r', port); break;<br >
+ case '\n': port_write_character(port)(sc, 'n', port); break;<br >
case '\b': port_write_character(port)(sc, 'b', port); break;<br >
case '\f': port_write_character(port)(sc, 'f', port); break;<br >
case '\?': port_write_character(port)(sc, '?', port); break;<br >
-- <br >
2.51.0<br ><br ></div></div><div style="line-height: 20px; clear: both;"><br ></div></div></div>