Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix current url_options without a port (default port) #43

Merged
merged 1 commit into from
Sep 7, 2024

Conversation

albus522
Copy link
Contributor

If no port is specified on ActiveStorage::Current.url_options current_host would return nil instead of "http://example.com"

Copy link
Owner

@blocknotes blocknotes left a comment

Choose a reason for hiding this comment

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

Thank you for your PR @albus522

@@ -20,7 +20,8 @@ def compose(source_keys, destination_key, **)
def current_host
opts = url_options || {}
url = "#{opts[:protocol]}#{opts[:host]}"
url + ":#{opts[:port]}" if opts[:port]
url += ":#{opts[:port]}" if opts[:port]
Copy link
Owner

Choose a reason for hiding this comment

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

What about using << instead?

Suggested change
url += ":#{opts[:port]}" if opts[:port]
url << ":#{opts[:port]}" if opts[:port]

Copy link
Contributor Author

@albus522 albus522 Mar 11, 2024

Choose a reason for hiding this comment

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

That is not a good idea while you still support ruby 2.7. Ruby 3 updated the frozen string literal setting to account for dynamic string literals, but ruby 2.7 will error can't modify frozen String for anyone that has turned that on globally because you have it enabled.

Copy link
Owner

Choose a reason for hiding this comment

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

Sorry for the late reply.

+= duplicates the string (you can make a test with object_id)

You can setup an unfrozen string when you are preparing it:
url = +"#{opts[:protocol]}#{opts[:host]}"

@blocknotes
Copy link
Owner

Also: please rebase your PR, the tests should work then.

@albus522
Copy link
Contributor Author

Rebased

@blocknotes blocknotes self-requested a review September 7, 2024 12:06
@blocknotes blocknotes dismissed their stale review September 7, 2024 12:06

Addressing changes later

@blocknotes blocknotes merged commit f8e9b14 into blocknotes:main Sep 7, 2024
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