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

Enable URLs with querystring #117

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## CHANGELOG

#### 0.6.x

* Fix issue with URLs with querystring

#### 0.6.17

* Upgraded to node-srs@1.x and generic-pool2.4.x
Expand Down
2 changes: 1 addition & 1 deletion lib/millstone.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ function resolve(options, callback) {
function localizeCartoURIs(s,cb) {
// Get all unique URIs in stylesheet
// TODO - avoid finding non url( uris?
var matches = s.data.match(/[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi);
var matches = s.data.match(/[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)/gi);
var URIs = _.uniq(matches || []);
var CartoURIs = [];
// remove any matched urls that are not clearly
Expand Down
14 changes: 14 additions & 0 deletions test/image-querystring/project-no-querystring.mml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"Stylesheet": [
"style-no-querystring.mss"
],
"Layer": [
{
"name": "background-image-no-querystring",
"Datasource": {
"type": "csv",
"inline": "x,y\n0,0"
}
}
]
}
14 changes: 14 additions & 0 deletions test/image-querystring/project-querystring.mml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"Stylesheet": [
"style-querystring.mss"
],
"Layer": [
{
"name": "background-image-querystring",
"Datasource": {
"type": "csv",
"inline": "x,y\n0,0"
}
}
]
}
1 change: 1 addition & 0 deletions test/image-querystring/style-no-querystring.mss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Map {background-image: url('http://i.imgur.com/yvRISk8.png');}
1 change: 1 addition & 0 deletions test/image-querystring/style-querystring.mss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Map {background-image: url('http://i.imgur.com/yvRISk8.png?foo=bar');}
59 changes: 59 additions & 0 deletions test/image-url-querystring.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
var fs = require('fs');
var path = require('path');
var assert = require('assert');

// switch to 'development' for more verbose logging
process.env.NODE_ENV = 'production'
var utils = require('../lib/util.js');
var millstone = require('../lib/millstone');
var tests = module.exports = {};
var rm = require('./support.js').rm;

var existsSync = require('fs').existsSync || require('path').existsSync;

var cache = '/tmp/millstone-test';

beforeEach(function(){
rm(path.join(__dirname, '/tmp/millstone-test'));

try {
fs.mkdirSync(options.cache, 0777);
} catch (e) {}
});


it('correctly handles images with no query string', function(done) {
var mml = JSON.parse(fs.readFileSync(path.join(__dirname, 'image-querystring/project-no-querystring.mml')));

var options = {
mml: mml,
base: path.join(__dirname, 'image-querystring'),
cache: cache
};

millstone.resolve(options, function(err, resolved) {
assert.equal(err,undefined,err);
assert.equal(resolved.Stylesheet[0].id, 'style-no-querystring.mss');
assert.equal(resolved.Stylesheet[0].data, "Map {background-image: url('/tmp/millstone-test/7b53c4b2-yvRISk8.png');}");
assert.ok(existsSync('/tmp/millstone-test/7b53c4b2-yvRISk8.png'));
done();
});
});

it('correctly handles images with query string', function(done) {
var mml = JSON.parse(fs.readFileSync(path.join(__dirname, 'image-querystring/project-querystring.mml')));

var options = {
mml: mml,
base: path.join(__dirname, 'image-querystring'),
cache: cache
};

millstone.resolve(options, function(err, resolved) {
assert.equal(err,undefined,err);
assert.equal(resolved.Stylesheet[0].id, 'style-querystring.mss');
assert.equal(resolved.Stylesheet[0].data, "Map {background-image: url('/tmp/millstone-test/d855a872-yvRISk8.png');}");
assert.ok(existsSync('/tmp/millstone-test/d855a872-yvRISk8.png'));
done();
});
});