-
Notifications
You must be signed in to change notification settings - Fork 159
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 invalid hostnames on platform creation #1652
base: main
Are you sure you want to change the base?
Conversation
The preview deployment is in progress. 🟡 Last updated at: 2025-02-27 14:29:14 CET |
The preview deployment is in progress. 🟡 Last updated at: 2025-02-27 14:29:15 CET |
The preview deployment is in progress. 🟡 Last updated at: 2025-02-27 14:29:16 CET |
The preview deployment is in progress. 🟡 Last updated at: 2025-02-27 14:29:17 CET |
// double-check the hostname value. | ||
if (platform === PlatformType.Flutterweb && !isHostnameValid($createPlatform.hostname)) { | ||
throw new Error('Please enter a valid hostname'); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we typically pass a regex to the input for these kinds of validations. Why can't we do that here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- extracted function can be helpful for future
- We could use regex pattern, but this way also helps in disabling the next button
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-usable is good.
I still have some concerns:
- This pattern is different compared to other places in the Console.
- There is little feedback to the user about what's wrong.
For example, here:

Yes, the button is disabled, but I don't know why. Compared to other places like create document:

As you can see for the asdf
attribute, there's more feedback to the developer about what's wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I can add a regex with the existing logic and that should give a clearer idea on why its disabled. Thanks for the screenshots 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stnguyen90 made a few changes to overall logic. It doesn't seem possible to directly manage the warning helper via the InputText
due to regex complexity as Svelte breaks it. Let me know if the newer changes are OK (backwards compatible).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya, we've dealt the regex problem in the past. It seems there's a special type of regex that's used in HTML inputs. See 4c416c7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we update the inputText input to expose a pattern and patternError like inputOTP:
console/src/lib/elements/forms/inputOTP.svelte
Lines 12 to 13 in e5ab426
export let pattern: string = null; | |
export let patternError: string = ''; |
As for the pattern, I think this should work:
const pattern = String.raw`(\*\.)?(?!-)[A-Za-z0-9\-]+([\-\.]{1}[a-z0-9]+)*\.[A-Za-z]{2,18}`;
We might also want to create a new input because we're going to also need it on the update platform pages such as:
console/src/routes/(console)/project-[project]/overview/platforms/[platform]/web.svelte
Lines 48 to 53 in e5ab426
<InputText | |
id="hostname" | |
label="Hostname" | |
bind:value={hostname} | |
required | |
placeholder="myapp.com" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That regex wouldn't have allowed *
, updated with latest changes. No changes to wizard required now.
// double-check the hostname value. | ||
if (platform === PlatformType.Flutterweb && !isHostnameValid($createPlatform.hostname)) { | ||
throw new Error('Please enter a valid hostname'); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we update the inputText input to expose a pattern and patternError like inputOTP:
console/src/lib/elements/forms/inputOTP.svelte
Lines 12 to 13 in e5ab426
export let pattern: string = null; | |
export let patternError: string = ''; |
As for the pattern, I think this should work:
const pattern = String.raw`(\*\.)?(?!-)[A-Za-z0-9\-]+([\-\.]{1}[a-z0-9]+)*\.[A-Za-z]{2,18}`;
We might also want to create a new input because we're going to also need it on the update platform pages such as:
console/src/routes/(console)/project-[project]/overview/platforms/[platform]/web.svelte
Lines 48 to 53 in e5ab426
<InputText | |
id="hostname" | |
label="Hostname" | |
bind:value={hostname} | |
required | |
placeholder="myapp.com" /> |
What does this PR do?
Fixes an issue where invalid hostnames were allowed for web platforms.
Test Plan
Manual.
Related PRs and Issues
Have you read the Contributing Guidelines on issues?
Yes.