Skip to content

Commit

Permalink
Merge pull request #97 from perimetre/9.2.5
Browse files Browse the repository at this point in the history
9.2.5
  • Loading branch information
adarleyjrr authored Jan 18, 2023
2 parents effede0 + d86d4f1 commit 9827cc1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

## [9.2.5] 2023-01-18

### Fixed

- Fixed a bug that would cause rich text editor to fail validation (or break while validating) for complex links

## [9.2.4] 2023-01-04

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@perimetre/ui",
"description": "A component library made by @perimetre",
"version": "9.2.4",
"version": "9.2.5",
"repository": {
"type": "git",
"url": "git+https://github.com/perimetre/ui.git"
Expand Down
18 changes: 10 additions & 8 deletions src/components/WYSIWYGInput/Toolbar/Options/Hyperlink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import { Dropdown } from '../../../Dropdown';
import { TextInput } from '../../../TextInput';
import { WYSIWYGTranslations } from '../../translations';

/**
* Ref: https://stackoverflow.com/a/65810131
*/
const URL =
/^((https?|ftp):\/\/)?(www.)?(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i;

type HyperlinkProps = {
/**
* The translation object
Expand Down Expand Up @@ -106,14 +112,10 @@ export const Hyperlink: React.FC<HyperlinkProps> = ({ translations, isActive, ed
// This is useful because the user can delete a link by not typing anything
// So we only validate if the user has typed something, or else the user wouldn't be able
// To continue with no text
link && link.length > 0
? schema
.matches(
/((https?):\/\/)?(www.)?[a-z0-9-]+(\.[a-z]{2,}){1,3}(#?\/?[a-zA-Z0-9#-]+)*\/?(\?[a-zA-Z0-9-_]+=[a-zA-Z0-9-%]+&?)?$/,
translations.linkErrorLabel
)
.required()
: schema
//
// We are using a custom regex to validate the url instead of yup.url()
// because yup validator is too strict and won't accept urls starting only with www.
link && link.length > 0 ? schema.matches(URL, translations.linkErrorLabel).required() : schema
)
.label(translations.linkInputLabel)
}),
Expand Down

0 comments on commit 9827cc1

Please sign in to comment.