From 294aacd27dcd4f8b4ee842139d2b0bf7fe2fd357 Mon Sep 17 00:00:00 2001 From: jakepruitt Date: Thu, 23 Jul 2015 17:52:02 -0400 Subject: [PATCH] Adding special case for non-fontstack "glyph" resource URLs - 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 --- js/util/mapbox.js | 5 ++++- test/js/util/mapbox.test.js | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/js/util/mapbox.js b/js/util/mapbox.js index 68f8ef0cd88..4a8d4eda080 100644 --- a/js/util/mapbox.js +++ b/js/util/mapbox.js @@ -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) { diff --git a/test/js/util/mapbox.test.js b/test/js/util/mapbox.test.js index 6b149f59ec6..af7975cef97 100644 --- a/test/js/util/mapbox.test.js +++ b/test/js/util/mapbox.test.js @@ -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();