-
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 wrong validation of projectid #571
Closed
nick2432
wants to merge
1
commit into
appwrite:main
from
nick2432:fix-6279-project-id-wrong-validation
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<script lang="ts"> | ||
import { onMount } from 'svelte'; | ||
import { FormItem } from '.'; | ||
import TextCounter from './textCounter.svelte'; | ||
|
||
export let value = ''; | ||
export let autofocus = true; | ||
|
||
let element: HTMLInputElement; | ||
let icon = 'info'; | ||
const pattern = String.raw`^[a-z0-9][a-z0-9-]{1,35}$`; | ||
|
||
onMount(() => { | ||
if (element && autofocus) { | ||
element.focus(); | ||
} | ||
}); | ||
|
||
const handleInvalid = (event: Event) => { | ||
event.preventDefault(); | ||
|
||
if (element.validity.patternMismatch) { | ||
icon = 'exclamation'; | ||
return; | ||
} | ||
}; | ||
|
||
$: if (value) { | ||
icon = 'info'; | ||
} | ||
</script> | ||
|
||
<FormItem> | ||
<div class="input-text-wrapper"> | ||
<input | ||
id="id" | ||
placeholder="Enter ID" | ||
maxlength={36} | ||
{pattern} | ||
autocomplete="off" | ||
type="text" | ||
class="input-text" | ||
bind:value | ||
bind:this={element} | ||
on:invalid={handleInvalid} /> | ||
<TextCounter count={value?.length ?? 0} max={36} /> | ||
</div> | ||
</FormItem> | ||
<div | ||
class="u-flex u-gap-4 u-margin-block-start-8 u-small" | ||
class:u-color-text-warning={icon === 'exclamation'}> | ||
<span | ||
class:icon-info={icon === 'info'} | ||
class:icon-exclamation={icon === 'exclamation'} | ||
class="u-cross-center u-line-height-1 u-color-text-gray" | ||
aria-hidden="true" /> | ||
<span class="text u-line-height-1-5"> | ||
Allowed characters: lowercase alphanumeric character and non-leading hyphen | ||
nick2432 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</span> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import '@testing-library/jest-dom'; | ||
import { render } from '@testing-library/svelte'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { InputProjectId } from '../../../src/lib/elements/forms'; | ||
|
||
const validStrings = ['validstring', 'valid-string', 'validstring123', 'valid-']; | ||
|
||
const invalidStrings = ['-invalid', 'Valid', '_invalid', 'Valid123', 'valid.string']; | ||
|
||
test('shows id input', () => { | ||
const { getByPlaceholderText } = render(InputProjectId); | ||
const input = getByPlaceholderText('Enter ID'); | ||
|
||
expect(input).toBeInTheDocument(); | ||
expect(input).toHaveAttribute('type', 'text'); | ||
}); | ||
|
||
test('state', async () => { | ||
const { component, getByPlaceholderText } = render(InputProjectId, { value: '' }); | ||
const input = getByPlaceholderText('Enter ID'); | ||
|
||
expect(component.value).toEqual(''); | ||
await userEvent.type(input, 'lorem'); | ||
expect(component.value).toEqual('lorem'); | ||
}); | ||
|
||
validStrings.forEach((validString) => { | ||
test(`validates ${validString} as valid`, () => { | ||
const { getByPlaceholderText } = render(InputProjectId, { value: validString }); | ||
const input = getByPlaceholderText('Enter ID') as HTMLInputElement; | ||
expect(input.checkValidity()).toBe(true); | ||
}); | ||
}); | ||
invalidStrings.forEach((invalidString) => { | ||
test(`validates ${invalidString} as invalid`, () => { | ||
const { getByPlaceholderText } = render(InputProjectId, { value: invalidString }); | ||
const input = getByPlaceholderText('Enter ID') as HTMLInputElement; | ||
expect(input.checkValidity()).toBe(false); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Something seems wrong with this pattern when it actually gets built. in the browser console logs i see:
And it doesn't look like the client-side validation works because the network request is sent despite the invalid id: