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 invalid hostnames on platform creation #1652

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ItzNotABug
Copy link
Member

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.

@ItzNotABug ItzNotABug self-assigned this Feb 8, 2025
@coolify-appwrite-org
Copy link

coolify-appwrite-org bot commented Feb 8, 2025

The preview deployment is in progress. 🟡

Open Build Logs

Last updated at: 2025-02-27 14:29:14 CET

@coolify-appwrite-org
Copy link

coolify-appwrite-org bot commented Feb 8, 2025

The preview deployment is in progress. 🟡

Open Build Logs

Last updated at: 2025-02-27 14:29:15 CET

@coolify-appwrite-org
Copy link

coolify-appwrite-org bot commented Feb 8, 2025

The preview deployment is in progress. 🟡

Open Build Logs

Last updated at: 2025-02-27 14:29:16 CET

@coolify-appwrite-org
Copy link

coolify-appwrite-org bot commented Feb 8, 2025

The preview deployment is in progress. 🟡

Open Build Logs

Last updated at: 2025-02-27 14:29:17 CET

Comment on lines 88 to 92
// double-check the hostname value.
if (platform === PlatformType.Flutterweb && !isHostnameValid($createPlatform.hostname)) {
throw new Error('Please enter a valid hostname');
}

Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. extracted function can be helpful for future
  2. We could use regex pattern, but this way also helps in disabling the next button

Copy link
Contributor

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:

  1. This pattern is different compared to other places in the Console.
  2. There is little feedback to the user about what's wrong.

For example, here:

image

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

image

As you can see for the asdf attribute, there's more feedback to the developer about what's wrong.

Copy link
Member Author

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 👍

Copy link
Member Author

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).

Copy link
Contributor

@stnguyen90 stnguyen90 Feb 26, 2025

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

Copy link
Contributor

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:

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:

<InputText
id="hostname"
label="Hostname"
bind:value={hostname}
required
placeholder="myapp.com" />

Copy link
Member Author

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.

Comment on lines 88 to 92
// double-check the hostname value.
if (platform === PlatformType.Flutterweb && !isHostnameValid($createPlatform.hostname)) {
throw new Error('Please enter a valid hostname');
}

Copy link
Contributor

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:

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:

<InputText
id="hostname"
label="Hostname"
bind:value={hostname}
required
placeholder="myapp.com" />

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.

3 participants