@@ -314,6 +314,70 @@ export_from_env_file() {
314314 [[ " $output " == * " is not in NAME=VALUE format" * ]]
315315}
316316
317+ # --- env_file CRLF handling (issue #28) -----------------------------------------------
318+
319+ @test " env_file strips CRLF line endings from values (issue #28)" {
320+ # GitHub's web form saves multi-line secrets as CRLF. Every line except the
321+ # last ends in \r, which becomes part of the value unless stripped.
322+ # Use $'...' syntax to embed literal CRLF in the string.
323+ export_from_env_file $' DB_USER=plone\r\n DB_PORT=5432\r\n ' DB_USER
324+ [ " $status " -eq 0 ]
325+ [ " $output " = " plone" ]
326+ }
327+
328+ @test " env_file strips CRLF from multiple values without corruption (issue #28)" {
329+ export_from_env_file $' DB_USER=admin\r\n DB_PASS=secret\r\n DB_HOST=localhost\r\n ' DB_PASS
330+ [ " $status " -eq 0 ]
331+ [ " $output " = " secret" ]
332+ }
333+
334+ @test " env_file reports stripped carriage returns (issue #28)" {
335+ # Like trim_inputs, the fix must report on stdout so the user sees the issue.
336+ run env -i PATH=" ${PATH} " HOME=" ${BATS_TEST_TMPDIR} " \
337+ ENV_FILE=$' DB_USER=plone\r\n ' \
338+ bash -c "
339+ source '${ENTRYPOINT} '
340+ ENV_FILE_DEST=\"\$ {HOME}/.env\"
341+ configure_env_file
342+ "
343+ [ " $status " -eq 0 ]
344+ [[ " $output " == * " Environment Variables: removed carriage returns from 1 line" * ]]
345+ }
346+
347+ @test " env_file counts multiple CRLF strips in the report (issue #28)" {
348+ run env -i PATH=" ${PATH} " HOME=" ${BATS_TEST_TMPDIR} " \
349+ ENV_FILE=$' DB_USER=admin\r\n DB_PASS=secret\r\n DB_HOST=localhost\r\n ' \
350+ bash -c "
351+ source '${ENTRYPOINT} '
352+ ENV_FILE_DEST=\"\$ {HOME}/.env\"
353+ configure_env_file
354+ "
355+ [ " $status " -eq 0 ]
356+ [[ " $output " == * " Environment Variables: removed carriage returns from 3 lines" * ]]
357+ }
358+
359+ @test " env_file with LF-only lines does not report carriage returns (issue #28)" {
360+ # Verify the fix doesn't report when there are no CR chars to strip.
361+ export_from_env_file $' DB_USER=plone\n DB_PORT=5432' DB_USER
362+ [ " $status " -eq 0 ]
363+ [[ ! " $output " =~ " carriage returns" ]]
364+ }
365+
366+ @test " env_file with blank lines after CRLF stripping does not abort (issue #28)" {
367+ # If a line only contained \r, after stripping it becomes empty and should
368+ # be skipped gracefully without aborting.
369+ export_from_env_file $' DB_USER=admin\r\n\r\n DB_PASS=secret\r\n ' DB_USER
370+ [ " $status " -eq 0 ]
371+ [ " $output " = " admin" ]
372+ }
373+
374+ @test " env_file with CRLF comment lines skips them correctly (issue #28)" {
375+ # Comments ending in CR should still be recognized and skipped.
376+ export_from_env_file $' # config\r\n DB_USER=plone\r\n ' DB_USER
377+ [ " $status " -eq 0 ]
378+ [ " $output " = " plone" ]
379+ }
380+
317381# --- env_file_path (issue #3) -------------------------------------------------
318382
319383# Write a file with the given content, run configure_env_file_path against it,
@@ -425,6 +489,49 @@ export_from_env_file_path() {
425489 [[ " $output " == * " Input remote_host is required!" * ]]
426490}
427491
492+ # --- env_file_path CRLF handling (issue #28) -------------------------------------------------
493+
494+ @test " env_file_path strips CRLF line endings from values (issue #28)" {
495+ # Files edited in Windows or via GitHub's web form may have CRLF line endings.
496+ local file=" ${BATS_TEST_TMPDIR} /crlf.env"
497+ printf ' %s' " $( printf ' DB_USER=admin\r\nDB_HOST=localhost\r\n' ) " > " ${file} "
498+ run env -i PATH=" ${PATH} " HOME=" ${BATS_TEST_TMPDIR} " \
499+ ENV_FILE_PATH=" ${file} " WANT=DB_USER \
500+ bash -c "
501+ source '${ENTRYPOINT} '
502+ configure_env_file_path >/dev/null 2>&1
503+ printf '[%s]' \"\$ {!WANT}\"
504+ "
505+ [ " $status " -eq 0 ]
506+ [ " $output " = " [admin]" ]
507+ }
508+
509+ @test " env_file_path reports stripped carriage returns (issue #28)" {
510+ local file=" ${BATS_TEST_TMPDIR} /crlf.env"
511+ printf ' %s' " $( printf ' DB_USER=admin\r\nDB_PASS=secret\r\n' ) " > " ${file} "
512+ run env -i PATH=" ${PATH} " HOME=" ${BATS_TEST_TMPDIR} " \
513+ ENV_FILE_PATH=" ${file} " \
514+ bash -c "
515+ source '${ENTRYPOINT} '
516+ configure_env_file_path
517+ "
518+ [ " $status " -eq 0 ]
519+ [[ " $output " == * " Environment Variables: removed carriage returns from 2 lines" * ]]
520+ }
521+
522+ @test " env_file_path with LF-only lines does not report carriage returns (issue #28)" {
523+ local file=" ${BATS_TEST_TMPDIR} /lf.env"
524+ printf ' %s\n' " DB_USER=admin" > " ${file} "
525+ run env -i PATH=" ${PATH} " HOME=" ${BATS_TEST_TMPDIR} " \
526+ ENV_FILE_PATH=" ${file} " \
527+ bash -c "
528+ source '${ENTRYPOINT} '
529+ configure_env_file_path
530+ "
531+ [ " $status " -eq 0 ]
532+ [[ ! " $output " =~ " carriage returns" ]]
533+ }
534+
428535# --- scale_after --------------------------------------------------------------
429536
430537@test " scale_after does nothing when unset" {
0 commit comments