Skip to content

Commit

Permalink
Adding special case for non-fontstack "glyph" resource URLs
Browse files Browse the repository at this point in the history
- does not prepend /v4/ to api endpoints like /fonts/v1/
- only prepends it to things starting with /fontstack
- solves the problem in #1385
- refs mapbox/mapbox-gl-style-spec#309
  • Loading branch information
jakepruitt committed Jul 23, 2015
1 parent 027a706 commit 294aacd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion js/util/mapbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ module.exports.normalizeGlyphsURL = function(url, accessToken) {
if (!url.match(/^mapbox:\/\//))
return url;

return normalizeURL(url, '/v4/', accessToken);
if (url.match(/^mapbox:\/\/fontstack/))
return normalizeURL(url, '/v4/', accessToken);

return normalizeURL(url, '/', accessToken);
};

module.exports.normalizeTileURL = function(url, sourceUrl) {
Expand Down
7 changes: 6 additions & 1 deletion test/js/util/mapbox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,16 @@ test("mapbox", function(t) {
});

t.test('.normalizeGlyphsURL', function(t) {
t.test('returns a v4 URL with access_token parameter', function(t) {
t.test('returns a v4 URL with access_token parameter for fontstack endpoint', function(t) {
t.equal(mapbox.normalizeGlyphsURL('mapbox://fontstack/{fontstack}/{range}.pbf'), 'https://a.tiles.mapbox.com/v4/fontstack/{fontstack}/{range}.pbf?access_token=key');
t.end();
});

t.test('returns a /fonts/v1 URL with access_token parameter for fonts endpoint', function(t) {
t.equal(mapbox.normalizeGlyphsURL('mapbox://fonts/v1/user/{fontstack}/{range}.pbf'), 'https://a.tiles.mapbox.com/fonts/v1/user/{fontstack}/{range}.pbf?access_token=key');
t.end();
});

t.test('ignores non-mapbox:// scheme', function(t) {
t.equal(mapbox.normalizeGlyphsURL('http://path'), 'http://path');
t.end();
Expand Down

0 comments on commit 294aacd

Please sign in to comment.