Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.27
0.0.28
6 changes: 6 additions & 0 deletions files/opencode-permissions-kit-lib/ddev-hosts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ DDEV_WIN_HOSTS="${DDEV_WIN_HOSTS:-/mnt/c/Windows/System32/drivers/etc/hosts}"
_ddev_hosts_yaml_list() {
[ -f "$1" ] || return 0
awk -v key="$2" '
# CRLF guard (issue #46): a Windows-edited config.yaml carries \r
# line endings; block-list items would keep theirs and the \r
# would end up mid-hostname ("name\r.tld") — it garbles terminal
# output (the tail overwrites the line start) and defeats the
# hosts-file grep, so an added hostname stays "missing" forever.
{ gsub(/\r/, "") }
$0 ~ "^[[:space:]]*" key ":" {
line = $0
sub(/^[^:]*:[[:space:]]*/, "", line)
Expand Down
27 changes: 27 additions & 0 deletions tests/test-ddev-hosts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,23 @@ assert_eq "list: name lowercased (ddev uses ToLower)" \
"with_upper_case.ddev.site" \
"$(sh -c '. "$1" && ddev_hosts_list "$2"' _ "$HOSTS" "$WORK/proj3")"

# issue #46: config.yaml with Windows CRLF line endings — block-list items
# kept their \r and it ended up mid-hostname ("name\r.tld"): the terminal
# renders the tail at column 0 (".localosts (win)", ".localdd:") and the
# hosts-file grep never matches, so an added hostname stays "missing".
mkdir -p "$WORK/projcrlf/.ddev"
printf 'name: crlf-proj\r\nproject_tld: local\r\nadditional_hostnames:\r\n - extra\r\nadditional_fqdns:\r\n - full.example.com\r\n' > "$WORK/projcrlf/.ddev/config.yaml"
assert_eq "list: CRLF config.yaml yields clean hostnames (issue #46)" \
"crlf-proj.local
extra.local
full.example.com" \
"$(sh -c '. "$1" && ddev_hosts_list "$2" | sort' _ "$HOSTS" "$WORK/projcrlf")"
if sh -c '. "$1" && ddev_hosts_list "$2"' _ "$HOSTS" "$WORK/projcrlf" | grep -q "$(printf '\r')"; then
fail "list: CR byte leaked into hostname output (issue #46)"
else
pass "list: no CR byte in hostname output (issue #46)"
fi

# --- 2. missing check against the Windows hosts file --------------------------

printf '127.0.0.1 localhost\n127.0.0.1 base-typo3-modulset.local other.local\n' > "$WORK/winhosts"
Expand All @@ -115,6 +132,16 @@ assert_eq "missing: substring hosts do not satisfy the check" \
"base-typo3-modulset.local" \
"$(DDEV_WIN_HOSTS="$WORK/winhosts2" sh -c '. "$1" && ddev_hosts_missing "$2"' _ "$HOSTS" "$WORK/proj1")"

# issue #46 follow-up: a hostname parsed from a CRLF config.yaml must
# match a cleanly added hosts entry (and a CRLF hosts file) — otherwise
# status reports it missing forever no matter how often the user adds it.
printf '127.0.0.1 crlf-proj.local extra.local full.example.com\n' > "$WORK/winhostscrlf"
assert_eq "missing: CRLF-parsed hostnames match clean hosts entries (issue #46)" "" \
"$(DDEV_WIN_HOSTS="$WORK/winhostscrlf" sh -c '. "$1" && ddev_hosts_missing "$2"' _ "$HOSTS" "$WORK/projcrlf")"
printf '127.0.0.1 crlf-proj.local extra.local full.example.com\r\n' > "$WORK/winhostscrlf"
assert_eq "missing: CRLF hosts entries still count as present (issue #46)" "" \
"$(DDEV_WIN_HOSTS="$WORK/winhostscrlf" sh -c '. "$1" && ddev_hosts_missing "$2"' _ "$HOSTS" "$WORK/projcrlf")"

# Unreadable/absent hosts file: everything counts as missing (hint shows).
assert_eq "missing: absent hosts file => all hostnames reported" \
"base-typo3-modulset.local" \
Expand Down