editor.js icon indicating copy to clipboard operation
editor.js copied to clipboard

[Bug] Pasted link cannot include spaces

Open rk opened this issue 3 years ago • 1 comments

I kept getting a front-end validation error when checking a link my client provided. Here's a sample one:

http://www.example.com/my-document v12.3.xslx

This is a valid URL when URL encoded to:

http://www.example.com/my-document%20v12.3.xslx

The average person who uses these code editors won't know about spaces in URLs, and most other tools tolerate the spaces. My search turned up this as the culprit:

https://github.com/codex-team/editor.js/blob/9cdda110dac04c70cf137ef324085e5326c448ec/src/components/inline-tools/inline-tool-link.ts#L326-L337

Maybe improving it to prefix search for http:, https:, or / would be better?

/^(http?s:|\/)/.test(str)

Steps to reproduce:

  1. https://editorjs.io/
  2. Select text in the editor
  3. Insert an inline link to http://www.example.com/my-document v12.3.xslx
  4. Note the URL validation error.

Expected behavior:

  • It should insert the link, optionally URL encoding it.

Screenshots:

Device, Browser, OS: any

Editor.js version: current

rk avatar Aug 11 '21 13:08 rk