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

fix(helpers, tag plugins): encode url by default #3710

Merged
merged 14 commits into from
Oct 7, 2019

Conversation

curbengh
Copy link
Contributor

What does it do?

Continuation of #3708, this PR deals with helpers and tag plugins.

How to test

git clone -b encode-url-helper https://github.com/curbengh/hexo.git
cd hexo
npm install
npm test

Pull request tasks

  • Add test cases for the changes.
  • Passed the CI test.

@curbengh
Copy link
Contributor Author

Depending on use case, asset_path tag plugin might not need to encode url.

@coveralls
Copy link

coveralls commented Sep 11, 2019

Coverage Status

Coverage decreased (-0.01%) to 97.237% when pulling 382b0de on curbengh:encode-url-helper into ffe4eaa on hexojs:master.

@curbengh curbengh changed the title fix(helpers, tag plugins): encode url by default WIP fix(helpers, tag plugins): encode url by default Sep 11, 2019
@curbengh
Copy link
Contributor Author

url_for pending hexojs/hexo-util#82

@SukkaW
Copy link
Member

SukkaW commented Sep 14, 2019

Should we re-implement those helper using hexo-util?

For example:

// url_for.js
'use strict';

module.exports = function (path = '/', options) {
  const url_for = require('hexo-util').url_for.bind(this);
  return url_for(path, options)
};

@curbengh
Copy link
Contributor Author

curbengh commented Sep 15, 2019

Should we re-implement those helper using hexo-util?

Definitely, once hexo-util v1.2.0 is published. To be refactored (in a separate PR):

  • relative_url
  • gravatar
  • full_url_for

@curbengh curbengh changed the title WIP fix(helpers, tag plugins): encode url by default fix(helpers, tag plugins): encode url by default Sep 15, 2019
@curbengh curbengh requested a review from a team September 15, 2019 11:18
@curbengh
Copy link
Contributor Author

curbengh commented Sep 15, 2019

Ready to review.


Just realized path is encoded twice if it's already encode (/foo/bar%20baz -> /foo/bar%25%20baz). Pending hexojs/hexo-util#92

tomap
tomap previously approved these changes Sep 16, 2019
@curbengh
Copy link
Contributor Author

curbengh commented Sep 16, 2019

WIP, needs to utilize url_for() more.

Edit: refactored.

@curbengh curbengh changed the title fix(helpers, tag plugins): encode url by default WIP fix(helpers, tag plugins): encode url by default Sep 16, 2019
@curbengh curbengh changed the title WIP fix(helpers, tag plugins): encode url by default fix(helpers, tag plugins): encode url by default Sep 18, 2019
@curbengh curbengh requested a review from tomap September 18, 2019 11:20
@curbengh
Copy link
Contributor Author

Pending hexojs/hexo-util#92 & hexojs/hexo-util#94 to avoid encoding path twice.

@curbengh curbengh mentioned this pull request Sep 19, 2019
2 tasks
@SukkaW
Copy link
Member

SukkaW commented Sep 20, 2019

I have no idea why the test on AppVeyor failed while the test on Travis CI successed.

SukkaW
SukkaW previously approved these changes Sep 20, 2019
@curbengh
Copy link
Contributor Author

curbengh commented Sep 21, 2019

I have no idea why the test on AppVeyor failed while the test on Travis CI successed.

The test failure shows the actual is "/foo%5Cbar" where %5C is a backslash, so it's Windows path.

This PR replaces url.resolve('/', asset.path); with encodeURL('/' + asset.path), the removal of url.resolve() could be the cause. I'll try putting it back, in combination with encodeURL.


Seems to resolve it, now left double-encoding issue.
Pending hexojs/hexo-util#92 & hexojs/hexo-util#99


Looks like full_url_for() and url_for() currently don't support Windows path. Perhaps adding url.resolve() in those functions can help.

Edit: url.resolve() in full_url_for() wouldn't help

const { resolve } = require('url')
console.log(resolve('http://example.com/blog/', 'abc\hey\index.html'))
// http://example.com/blog/abcheyindex.html

Anyhow, Windows path may not be applicable for full_url_for() / url_for().

@curbengh
Copy link
Contributor Author

curbengh commented Sep 22, 2019

html_tag of hexo-util needs to be updated for mail_to helper compatibility.


Located the issue:

const { parse } = require('url')
console.log(parse('mailto:abc@example.com'))
/*
Url {
  protocol: 'mailto:',
  slashes: null,
  auth: 'abc',
  host: 'example.com',
  port: null,
  hostname: 'example.com',
  hash: null,
  search: null,
  query: null,
  pathname: null,
  path: null,
  href: 'mail:abc@example.com'
}
*/

null path is appended, resulting in mailto:abc@example.comnull.


Fix created hexojs/hexo-util#102

@curbengh curbengh requested a review from SukkaW October 7, 2019 07:42
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.

5 participants