Skip to content

Commit 425fa56

Browse files
committed
FIX: MOLD/FLAT on block values does not remove line breaks
fixes: metaeducation/rebol-issues#2388
1 parent 9f8464c commit 425fa56

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/core/s-mold.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ STOID Mold_Block_Series(REB_MOLD *mold, REBSER *series, REBCNT index, REBYTE *se
604604
REBOOL line_flag = FALSE; // newline was part of block
605605
REBOOL had_lines = FALSE;
606606
REBVAL *value = BLK_SKIP(series, index);
607+
REBOOL indented = !GET_MOPT(mold, MOPT_INDENT);
607608

608609
if (!sep) sep = b_cast("[]");
609610

@@ -631,7 +632,7 @@ STOID Mold_Block_Series(REB_MOLD *mold, REBSER *series, REBCNT index, REBYTE *se
631632
value = BLK_SKIP(series, index);
632633
while (NOT_END(value)) {
633634
if (VAL_GET_LINE(value)) {
634-
if (sep[1] || line_flag) New_Indented_Line(mold);
635+
if (indented && (sep[1] || line_flag)) New_Indented_Line(mold);
635636
had_lines = TRUE;
636637
}
637638
line_flag = TRUE;
@@ -643,7 +644,7 @@ STOID Mold_Block_Series(REB_MOLD *mold, REBSER *series, REBCNT index, REBYTE *se
643644

644645
if (sep[1]) {
645646
mold->indent--;
646-
if (VAL_GET_LINE(value) || had_lines) New_Indented_Line(mold);
647+
if (indented && (VAL_GET_LINE(value) || had_lines)) New_Indented_Line(mold);
647648
Append_Byte(out, sep[1]);
648649
}
649650

@@ -657,6 +658,7 @@ STOID Mold_Block(REBVAL *value, REB_MOLD *mold)
657658
REBSER *series = mold->series;
658659
REBFLG over = FALSE;
659660

661+
660662
if (SERIES_WIDE(VAL_SERIES(value)) == 0)
661663
Crash(RP_BAD_WIDTH, sizeof(REBVAL), 0, VAL_TYPE(value));
662664

src/tests/units/mold-test.r3

+20
Original file line numberDiff line numberDiff line change
@@ -241,4 +241,24 @@ Rebol [
241241

242242
===end-group===
243243

244+
===start-group=== "mold block!"
245+
b: [
246+
1 2
247+
3 4
248+
]
249+
c: reduce [
250+
"A"
251+
b
252+
]
253+
--test-- "mold/flat block!"
254+
;@@ https://github.com/rebol/rebol-issues/issues/2388
255+
--assert (mold/flat b) = "[1 2 3 4]"
256+
--assert (mold/flat c) = {["A" [1 2 3 4]]}
257+
258+
--test-- "mold/flat/all block!"
259+
--assert (mold/flat/all c) = {["A" [1 2 3 4]]}
260+
--assert (mold/flat/all next c) = {#[block! ["A" [1 2 3 4]] 2]}
261+
262+
===end-group===
263+
244264
~~~end-file~~~

0 commit comments

Comments
 (0)