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

Allow for relative paths when loading RTL plugin #6764

Merged
merged 1 commit into from
Jun 1, 2018

Conversation

ryanhamley
Copy link
Contributor

@ryanhamley ryanhamley commented May 30, 2018

Launch Checklist

  • briefly describe the changes in this PR
    • Allows for relative paths when loading RTL plugin
  • write tests for all new functionality
  • manually test the debug page

Closes #6719

const a = window.document.createElement('a');
a.href = path;
return a.href;
};
Copy link
Member

Choose a reason for hiding this comment

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

Looks like we're doing something similar in

function resolveURL(url) {
const a = window.document.createElement('a');
a.href = url;
return a.href;
}

Can we move that code to a more central place to avoid duplicating it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah thanks for pointing that out. Yeah, we should be able to centralize this somewhere.

const resolvePluginUrl = (path) => {
if (isAbsoluteUrl(path)) {
return path;
}
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to special case absolute URLs? It looks like we could also just happily pipe absolute/protocol-relative URLs through the a/href resolver. If we need this, it'd be a good idea to add the absolute URL special case to the GeoJSON resolver (see below) as well)

@kkaefer kkaefer dismissed their stale review May 31, 2018 19:17

didn't mean to deny

@ryanhamley
Copy link
Contributor Author

I'm not sure how to test this other than manually. There's no straightforward way to test this in the unit tests since Node doesn't have an window.location.origin and I don't think you can set it since origin is readonly. The render tests hardcode the plugin through an import statement and changing this to load the plugin via the setRTLTextPlugin method seems to break all the render tests. Any ideas? Am I overthinking this? It definitely works since it was tested on the debug page csp.html. @kkaefer

Copy link
Contributor

@jfirebaugh jfirebaugh left a comment

Choose a reason for hiding this comment

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

@ChrisLoer can correct me if I'm wrong, but I believe we've been relying on manual testing for the RTL plugin.

@ChrisLoer
Copy link
Contributor

I believe we've been relying on manual testing for the RTL plugin.

Mainly, yes, and I think testing manually with csp.html is probably the most important/effective test for this pathway. The style unit test has a "register plugin listener" test case that could easily be modified to test the handling of a relative path -- but as @ryanhamley pointed out that gets tripped up on not having a window.location.origin. I think you could probably use Sinon's stubbing to handle that, but you'd be testing a pretty narrow/contrived case.

Thanks for fixing this, Ryan!

@ryanhamley ryanhamley force-pushed the 6719-rtl-plugin-relative-path branch from 9fab797 to 7c95198 Compare June 1, 2018 20:26
@ryanhamley ryanhamley merged commit 7c95198 into master Jun 1, 2018
@ryanhamley ryanhamley deleted the 6719-rtl-plugin-relative-path branch June 1, 2018 20:38
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.

4 participants