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 access token validation logic for custom mapbox style URLs #4144

Merged
merged 1 commit into from
Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/plots/mapbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,10 @@ function findAccessToken(gd, mapboxIds) {
}

function isMapboxStyle(s) {
return typeof s === 'string' && constants.styleValuesMapbox.indexOf(s) !== -1;
return typeof s === 'string' && (
constants.styleValuesMapbox.indexOf(s) !== -1 ||
s.indexOf('mapbox://') === 0
);
}

exports.updateFx = function(gd) {
Expand Down
21 changes: 21 additions & 0 deletions test/jasmine/tests/mapbox_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,27 @@ describe('mapbox credentials', function() {
});
}, LONG_TIMEOUT_INTERVAL);

it('@gl should not throw when using a custom mapbox style URL with an access token in the layout', function(done) {
var cnt = 0;

Plotly.plot(gd, [{
type: 'scattermapbox',
lon: [10, 20, 30],
lat: [10, 20, 30]
}], {
mapbox: {
accesstoken: MAPBOX_ACCESS_TOKEN,
style: 'mapbox://styles/etpinard/cip93fm98000sbmnuednknloo'
}
}).catch(function() {
cnt++;
}).then(function() {
expect(cnt).toEqual(0);
expect(gd._fullLayout.mapbox.accesstoken).toBe(MAPBOX_ACCESS_TOKEN);
done();
});
}, LONG_TIMEOUT_INTERVAL);

it('@gl should log when an access token is set while using a custom non-mapbox style', function(done) {
spyOn(Lib, 'log');
var cnt = 0;
Expand Down