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

Disallow creating anchors with space characters #5362

Merged
merged 13 commits into from
Nov 21, 2022
Merged

Disallow creating anchors with space characters #5362

merged 13 commits into from
Nov 21, 2022

Conversation

KarolDawidziuk
Copy link
Contributor

What is the purpose of this pull request?

Bug fix

Does your PR contain necessary tests?

All patches that change the editor code must include tests. You can always read more
on PR testing,
how to set the testing environment and
how to create tests
in the official CKEditor documentation.

This PR contains

  • Unit tests
  • Manual tests

Did you follow the CKEditor 4 code style guide?

Your code should follow the guidelines from the CKEditor 4 code style guide which helps keep the entire codebase consistent.

  • PR is consistent with the code style guide

What is the proposed changelog entry for this pull request?

* [#5305](/~https://github.com/ckeditor/ckeditor4/issues/5305): Fixed. Anchor name can invalidly include spaces.

What changes did you make?

I've updated a validate method in anchor dialog by checking if the given name a space character.

Which issues does your PR resolve?

Closes #5305.

@Comandeer Comandeer self-assigned this Oct 31, 2022
@Comandeer Comandeer self-requested a review October 31, 2022 12:00
Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

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

Overall looks good! Just some minor things to polish.

tests/plugins/link/anchor.js Outdated Show resolved Hide resolved
tests/plugins/link/anchor.js Outdated Show resolved Hide resolved
tests/plugins/link/anchor.js Outdated Show resolved Hide resolved
tests/plugins/link/anchor.js Outdated Show resolved Hide resolved
tests/plugins/link/anchor.js Outdated Show resolved Hide resolved
tests/plugins/link/anchor.js Outdated Show resolved Hide resolved
@@ -136,10 +136,20 @@ CKEDITOR.dialog.add( 'anchor', function( editor ) {
label: editor.lang.link.anchor.name,
required: true,
validate: function() {
if ( !this.getValue() ) {
var disallowedWhitespacesRegex = /[\u0020\u0009\u000c]/g,
Copy link
Member

Choose a reason for hiding this comment

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

I would add also new line and carriage return characters here – just to be sure. They aren't possible to but they can be pasted from somewhere. Better safe than sorry.

It'd be also nice to link to the spec to explain why these characters are not allowed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a new line and carriage return character but I was not able to add a unit test to it as it was impossible to paste it to input. Are we okay with it? 🤔

I've also added also short information about disallowed characters from spec.

@@ -13,6 +13,7 @@ CKEDITOR.plugins.setLang( 'link', 'en', {
title: 'Anchor Properties',
name: 'Anchor Name',
errorName: 'Please type the anchor name',
errorWhitespace: 'Anchor name cannot contain whitespaces',
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
errorWhitespace: 'Anchor name cannot contain whitespaces',
errorWhitespace: 'Anchor name cannot contain any whitespace',

Whitespace is mostly used as an uncountable noun.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've changed it to a space character, not a whitespace.

tests/plugins/link/anchor.js Outdated Show resolved Hide resolved
@KarolDawidziuk
Copy link
Contributor Author

KarolDawidziuk commented Nov 4, 2022

Thanks, @Comandeer for the review - it's ready to another one.

@Comandeer
Copy link
Member

Rebased onto the latest master.

Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

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

Looks good, only some polishing needed.

There is also an error in IE8 connected to the tests:

Error: Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus.

Could you look into it?

@@ -136,10 +136,23 @@ CKEDITOR.dialog.add( 'anchor', function( editor ) {
label: editor.lang.link.anchor.name,
required: true,
validate: function() {
if ( !this.getValue() ) {
// W3C HTML 5.2 Recommendation; §3.2.5:
Copy link
Member

Choose a reason for hiding this comment

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

The HTML 5.2 specification does not longer exist. Could you update the reference to point to https://html.spec.whatwg.org/multipage/dom.html#global-attributes ?

@@ -13,6 +13,7 @@ CKEDITOR.plugins.setLang( 'link', 'en', {
title: 'Anchor Properties',
name: 'Anchor Name',
errorName: 'Please type the anchor name',
errorWhitespace: 'Anchor name cannot contain space character',
Copy link
Member

Choose a reason for hiding this comment

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

There is some small discrepancy between this message and the message in the manual test. IMO the version from the test ("space characters") sounds better than the version in language files ("space character").

Probably it's safer to consult it with our docs team to ensure that the grammatical form of the message is ok 🤔 It would be much harder to do that after the release.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After talking with @godai78 we have 3 possible options:

  1. Anchor name cannot contain space characters -> your version
  2. Anchor name cannot contain any spaces -> this may be not obvious
  3. Anchor name cannot contain any space characters

For me, 1 and 3 look equally good to me, WDYT?

@KarolDawidziuk
Copy link
Contributor Author

Thanks, @Comandeer for the review.
I've applied improvements mentioned in your comments and PR is ready for another check.

@Comandeer Comandeer self-assigned this Nov 21, 2022
Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

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

LGTM!

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.

Anchor name can invalidly include spaces
2 participants