Skip to content

Conversation

@Jocs
Copy link
Member

@Jocs Jocs commented Sep 16, 2019

Q A
Bug fix? no
License MIT

Description

Copy url link from browser address bar, and parse the page title as anchor text. for example:

Copy https://element.eleme.cn/#/zh-CN/component/tabs from browser address bar, and paste to Mark Text, it will looks like this 组件|Element

--

Please, don't submit /dist files with your PR!


This change is Reviewable

@Jocs Jocs merged commit 141d25d into develop Sep 17, 2019
const { response } = req
if (typeof response === 'string') {
const match = response.match(/<title>(.*)<\/title>/)
return match[1] ? settle(match[1]) : settle('')
Copy link
Contributor

Choose a reason for hiding this comment

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

@Jocs I think we should escape the title using DOMPurify to prevent possible XSS?

Copy link
Contributor

@fxha fxha Sep 20, 2019

Choose a reason for hiding this comment

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

BTW we should check if the array contains at least one title (length >= 2). I don't know what JS does if the index is out of bounds due missing title.

Copy link
Member Author

Choose a reason for hiding this comment

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

BTW we should check if the array contains at least one title (length >= 2). I don't know what JS does if the index is out of bounds due missing title.

it will always have match[1] if the match is not null.

One html page will have more than one title ? as far as I can see, html will only has one title.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is a missing match && match[1] or match && match.length >= 2 check. Otherwise an exception is thrown or segfault.

Copy link
Member Author

Choose a reason for hiding this comment

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

@fxha I'll make a PR to solve later.

const span = document.createElement('span')
span.innerHTML = text
link.replaceWith(span)
const title = await getPageTitle(href)
Copy link
Contributor

Choose a reason for hiding this comment

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

@Jocs Does this may cause problems when typing other stuff and getPageTitle take a long time or times out? Or is the editor block for this time?

E.g.

  1. Paste text with link in it
  2. getPageTitle http request (async)
  3. User: type random words
  4. http request (not) successful
  5. ???

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it does not be blocked, but it maybe take some time to request the page title, I set a timeout of 1.5 s, but it shouldn't be perfect. It's better to insert the link first, and then insert the anchor text (title content) after the title is obtained.

I will optimize before the 1.6 release.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it does not be blocked, but it maybe take some time to request the page title, I set a timeout of 1.5 s, but it shouldn't be perfect. It's better to insert the link first, and then insert the anchor text (title content) after the title is obtained.

I will optimize before the 1.6 release.

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.

3 participants