Skip to content

Commit

Permalink
fix: use less strict validation for external URLs
Browse files Browse the repository at this point in the history
Default url validation from the Yup module doesn't allow URLs like "http://custom-host", while it is
a correct value for an external URL.

fix #1068
  • Loading branch information
gauthier-th committed Nov 15, 2024
1 parent 5c24e79 commit ca323fa
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/components/Settings/RadarrModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ const RadarrModal = ({ onClose, radarr, onSave }: RadarrModalProps) => {
intl.formatMessage(messages.validationMinimumAvailabilityRequired)
),
externalUrl: Yup.string()
.url(intl.formatMessage(messages.validationApplicationUrl))
.matches(
/^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}(\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*))?$/i,

Check warning

Code scanning / CodeQL

Duplicate character in character class Warning

Character '/' is
repeated in the same character class
.
intl.formatMessage(messages.validationApplicationUrl)
)
.test(
'no-trailing-slash',
intl.formatMessage(messages.validationApplicationUrlTrailingSlash),
Expand Down
10 changes: 8 additions & 2 deletions src/components/Settings/SettingsJellyfin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,21 @@ const SettingsJellyfin: React.FC<SettingsJellyfinProps> = ({
),
jellyfinExternalUrl: Yup.string()
.nullable()
.url(intl.formatMessage(messages.validationUrl))
.matches(
/^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}(\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*))?$/i,

Check warning

Code scanning / CodeQL

Duplicate character in character class Warning

Character '/' is
repeated in the same character class
.
intl.formatMessage(messages.validationUrl)
)
.test(
'no-trailing-slash',
intl.formatMessage(messages.validationUrlTrailingSlash),
(value) => !value || !value.endsWith('/')
),
jellyfinForgotPasswordUrl: Yup.string()
.nullable()
.url(intl.formatMessage(messages.validationUrl))
.matches(
/^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}(\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*))?$/i,

Check warning

Code scanning / CodeQL

Duplicate character in character class Warning

Character '/' is
repeated in the same character class
.
intl.formatMessage(messages.validationUrl)
)
.test(
'no-trailing-slash',
intl.formatMessage(messages.validationUrlTrailingSlash),
Expand Down
5 changes: 4 additions & 1 deletion src/components/Settings/SettingsMain/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ const SettingsMain = () => {
intl.formatMessage(messages.validationApplicationTitle)
),
applicationUrl: Yup.string()
.url(intl.formatMessage(messages.validationApplicationUrl))
.matches(
/^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}(\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*))?$/i,

Check warning

Code scanning / CodeQL

Duplicate character in character class Warning

Character '/' is
repeated in the same character class
.
intl.formatMessage(messages.validationApplicationUrl)
)
.test(
'no-trailing-slash',
intl.formatMessage(messages.validationApplicationUrlTrailingSlash),
Expand Down
5 changes: 4 additions & 1 deletion src/components/Settings/SettingsPlex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ const SettingsPlex = ({ onComplete }: SettingsPlexProps) => {
otherwise: Yup.string().nullable(),
}),
tautulliExternalUrl: Yup.string()
.url(intl.formatMessage(messages.validationUrl))
.matches(
/^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}(\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*))?$/i,

Check warning

Code scanning / CodeQL

Duplicate character in character class Warning

Character '/' is
repeated in the same character class
.
intl.formatMessage(messages.validationUrl)
)
.test(
'no-trailing-slash',
intl.formatMessage(messages.validationUrlTrailingSlash),
Expand Down
5 changes: 4 additions & 1 deletion src/components/Settings/SonarrModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ const SonarrModal = ({ onClose, sonarr, onSave }: SonarrModalProps) => {
)
: Yup.number(),
externalUrl: Yup.string()
.url(intl.formatMessage(messages.validationApplicationUrl))
.matches(
/^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}(\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*))?$/i,

Check warning

Code scanning / CodeQL

Duplicate character in character class Warning

Character '/' is
repeated in the same character class
.
intl.formatMessage(messages.validationApplicationUrl)
)
.test(
'no-trailing-slash',
intl.formatMessage(messages.validationApplicationUrlTrailingSlash),
Expand Down

0 comments on commit ca323fa

Please sign in to comment.