Skip to content

Conversation

@emmadesilva
Copy link
Member

@emmadesilva emmadesilva commented Jun 12, 2024

Abstract

We're getting some issues by Hyde using localhost as the default site URL. Initially, this PR will target the 1.x branch because I consider these things to be bugs that should be fixed in v1, however, there may be side effects of this: primarily that output HTML will change - but I do not think anyone will depend on those undesired effects before this patch, since localhost is never desired in production. This will resolve #1720

Expanding on the reasoning behind allowing this in 1.x: Since v1 is LTS, I don't want to leave those users hanging with what is in my opinion a bug, that localhost links can "leak" through production. And I think the only way to fix this is by changing some logic which could have side effects. But I think I am okay with that tradeoff as it stands now, especially since I think any possible usages that may be affected probably don't actually desire the logic we have now.

Major changes

Method Hyde::hasSiteUrl() now returns false if URL is localhost

This better matches the documented method description of "Check if a site base URL has been set in config (or .env).", as this value is localhost by default and thus not set by the user.

Method Hyde::url() now resolves relative paths instead of throwing

We now return the relative path even if the base URL is not set, as this is more likely to be the desired behavior the user's expecting. If the user is trying to get the base URL, but it's not set, we throw the exception.

@emmadesilva emmadesilva linked an issue Jun 12, 2024 that may be closed by this pull request
@emmadesilva
Copy link
Member Author

emmadesilva commented Jun 12, 2024

We can probably update code added in #1660 to use the new logic. Edit: Resolved in 0bcb9f7

@emmadesilva emmadesilva force-pushed the ensure-a-better-state-when-a-site-url-is-not-set branch 3 times, most recently from 8efa960 to e71b1d5 Compare June 12, 2024 16:46
@codecov
Copy link

codecov bot commented Jun 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.95%. Comparing base (7fd4aa2) to head (0bcb9f7).
Report is 4 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1726      +/-   ##
============================================
- Coverage     99.97%   99.95%   -0.03%     
- Complexity     1746     1747       +1     
============================================
  Files           181      181              
  Lines          4667     4670       +3     
============================================
+ Hits           4666     4668       +2     
- Misses            1        2       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@emmadesilva emmadesilva force-pushed the ensure-a-better-state-when-a-site-url-is-not-set branch from 8ed2cc1 to 0439c16 Compare June 12, 2024 16:51
We now return the relative path even if the base URL is not set, as this is more likely to be the desired behavior the user's expecting. If the user is trying to get the base URL, but it's not set, we throw the exception.
@emmadesilva emmadesilva force-pushed the ensure-a-better-state-when-a-site-url-is-not-set branch from 0439c16 to 3cfa8a5 Compare June 12, 2024 17:01
This better matches the documented method description of "Check if a site base URL has been set in config (or .env).", as this value is `localhost` by default and thus not set by the user.

Revert "Method `Hyde::hasSiteUrl()` now returns false when URL is for localhost"

This reverts commit 8a13ad9.

Reapply "Method `Hyde::hasSiteUrl()` now returns false when URL is for localhost"

This reverts commit 0c4ab34.

Update HelpersTest.php
Only the Markdown pages can be made like this
}

// User is trying to get the base URL, but it's not set
throw new BaseUrlNotSetException();
Copy link
Member Author

Choose a reason for hiding this comment

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

We might consider this for deprecation

@emmadesilva emmadesilva marked this pull request as ready for review June 13, 2024 16:36
@emmadesilva emmadesilva merged commit 3d0151c into master Jun 13, 2024
@emmadesilva emmadesilva deleted the ensure-a-better-state-when-a-site-url-is-not-set branch June 13, 2024 16:37
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.

Ensure a better state when a site URL is not set

1 participant