Skip to content

Commit

Permalink
Merge pull request #4144 from plotly/mapbox-custom-style-url-fixup
Browse files Browse the repository at this point in the history
Fix access token validation logic for custom mapbox style URLs
  • Loading branch information
etpinard authored Aug 22, 2019
2 parents 2aec9ef + e5c3b41 commit 456d718
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
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

0 comments on commit 456d718

Please sign in to comment.