Skip to content

Conversation

@andrew-nowak
Copy link
Member

What does this change?

There's a grep call in add-to-hosts-file which aims to prevent adding duplicate entries. Unfortunately the regex is naive so will match a domain even if it doesn't exist and is only a substring of an existing domain. For example, if we've already added api.media.local.dev-gutools.co.uk, then the command will not allow us to add media.local.dev-gutools.co.uk as that domain appears to already exist.

Improve the match with grep's extended regex to match the entire line, from IP address, delimiting whitespace to domain name and end-of-line marker. Now dev-nginx should correctly deduplicate entries.

How to test

Run add-to-hosts-file api.media.local.dev-gutools.co.uk then add-to-hosts-file media.local.dev-gutools.co.uk - you should not get a message that the entry already exists. (remember to clean up your /etc/hosts file afterwards!)

@andrew-nowak andrew-nowak requested a review from Copilot August 11, 2025 17:23
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug in the add-to-hosts-file script where the grep regex was too permissive, causing false matches when checking for existing hosts file entries. The issue occurred when a domain was a substring of an already existing domain (e.g., media.local.dev-gutools.co.uk appearing to exist when only api.media.local.dev-gutools.co.uk was present).

  • Replaces the naive grep pattern with a stricter extended regex that matches the complete line format
  • Uses anchors and whitespace patterns to ensure exact domain matching rather than substring matching

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants