summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--src/wordsplit.c39
-rw-r--r--tests/wordsplit.at13
2 files changed, 36 insertions, 16 deletions
diff --git a/src/wordsplit.c b/src/wordsplit.c
index f94015a..e979f27 100644
--- a/src/wordsplit.c
+++ b/src/wordsplit.c
@@ -805,25 +805,35 @@ wordsplit_finish (struct wordsplit *wsp)
805 n++; 805 n++;
806 } 806 }
807 807
808 if (n == 0 && (wsp->ws_flags & WRDSF_INCREMENTAL)) 808 if (n == 0)
809 { 809 {
810 /* The loop above have eliminated all nodes. Restart the 810 /* The loop above have eliminated all nodes. */
811 processing, if there's any input left. */ 811 if (wsp->ws_flags & WRDSF_INCREMENTAL)
812 if (wsp->ws_endp < wsp->ws_len)
813 { 812 {
814 int rc; 813 /* Restart the processing, if there's any input left. */
815 if (wsp->ws_flags & WRDSF_SHOWDBG) 814 if (wsp->ws_endp < wsp->ws_len)
816 wsp->ws_debug (_("Restarting")); 815 {
817 rc = wordsplit_process_list (wsp, skip_delim (wsp)); 816 int rc;
818 if (rc) 817 if (wsp->ws_flags & WRDSF_SHOWDBG)
819 return rc; 818 wsp->ws_debug (_("Restarting"));
819 rc = wordsplit_process_list (wsp, skip_delim (wsp));
820 if (rc)
821 return rc;
822 }
823 else
824 {
825 wsp->ws_error = WRDSE_EOF;
826 return WRDSE_EOF;
827 }
828 goto again;
820 } 829 }
821 else 830
831 if (wsp->ws_flags & WRDSF_NOSPLIT)
822 { 832 {
823 wsp->ws_error = WRDSE_EOF; 833 if (wordsplit_add_segm (wsp, 0, 0, _WSNF_EMPTYOK))
824 return WRDSE_EOF; 834 return wsp->ws_errno;
835 n = 1;
825 } 836 }
826 goto again;
827 } 837 }
828 838
829 if (alloc_space (wsp, n + 1)) 839 if (alloc_space (wsp, n + 1))
@@ -2412,6 +2422,7 @@ wordsplit_process_list (struct wordsplit *wsp, size_t start)
2412 } 2422 }
2413 } 2423 }
2414 } 2424 }
2425
2415 return wsp->ws_errno; 2426 return wsp->ws_errno;
2416} 2427}
2417 2428
diff --git a/tests/wordsplit.at b/tests/wordsplit.at
index 631d939..e3af703 100644
--- a/tests/wordsplit.at
+++ b/tests/wordsplit.at
@@ -262,7 +262,7 @@ TOTAL: 2
262[], 262[],
263[FOO=bar BAZ=qux]) 263[FOO=bar BAZ=qux])
264 264
265TESTWSP([nosplit with expansion],[wsp-var-nosplit],[nosplit], 265TESTWSP([nosplit with variable expansion],[wsp-var-nosplit],[nosplit],
266[a $FOO test], 266[a $FOO test],
267[NF: 1 267[NF: 1
2680: "a variable expansion test\n" 2680: "a variable expansion test\n"
@@ -271,7 +271,7 @@ TOTAL: 1
271[], 271[],
272[FOO="variable expansion"]) 272[FOO="variable expansion"])
273 273
274TESTWSP([nosplit without expansion],[],[nosplit novar], 274TESTWSP([nosplit without variable expansion],[],[nosplit novar],
275[a $FOO test], 275[a $FOO test],
276[NF: 1 276[NF: 1
2770: "a $FOO test\n" 2770: "a $FOO test\n"
@@ -280,6 +280,15 @@ TOTAL: 1
280[], 280[],
281[FOO="variable expansion"]) 281[FOO="variable expansion"])
282 282
283TESTWSP([nosplit: empty expansion],[],[nosplit trimnl],
284[$FOO],
285[NF: 1
2860: ""
287TOTAL: 1
288],
289[],
290[FOO=""])
291
283TESTWSP([default value (defined)],[],[], 292TESTWSP([default value (defined)],[],[],
284[${FOO:-bar}], 293[${FOO:-bar}],
285[NF: 1 294[NF: 1

Return to:

Send suggestions and report system problems to the System administrator.