fix 1p recipes returned as 3p ones; preserve & show comments

pull/2/head
Raymond Hill 7 years ago
parent b793312143
commit 6958c4ed26
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

@ -50,9 +50,9 @@
hn = hn.slice(0, pos + hn.length - domain.length) + '.*'; hn = hn.slice(0, pos + hn.length - domain.length) + '.*';
} }
} }
if ( hn.endsWith(targetHostname) === false ) { if ( hn.endsWith(targetHostname) === false ) { return false; }
return false; let pos = hn.length - targetHostname.length;
} if ( pos !== 0 && hn.charAt(pos - 1) !== '.' ) { return false; }
} }
targetHostname = condition.slice(i + 1).trim(); targetHostname = condition.slice(i + 1).trim();
if ( targetHostname === '*' ) { return true; } if ( targetHostname === '*' ) { return true; }
@ -94,9 +94,10 @@
}; };
var fromString = function(raw) { var fromString = function(raw) {
var recipeName, let recipeName,
recipeCondition, recipeCondition,
recipeRuleset; recipeRuleset;
let reComment = /^[!#]/;
let rawHeader = raw.slice(0, 1024); let rawHeader = raw.slice(0, 1024);
if ( reValidRecipeFile.test(rawHeader) === false ) { return; } if ( reValidRecipeFile.test(rawHeader) === false ) { return; }
let maintainer = authorFromHeader(rawHeader); let maintainer = authorFromHeader(rawHeader);
@ -118,11 +119,12 @@
}); });
} }
recipeName = undefined; recipeName = undefined;
recipeCondition = undefined;
} }
if ( lineIter.eot() && recipeName === undefined ) { break; } if ( lineIter.eot() && recipeName === undefined ) { break; }
if ( line.length === 0 ) { continue; } if ( line.length === 0 ) { continue; }
let c = line.charCodeAt(0); let isComment = reComment.test(line);
if ( c === 0x23 /* '#' */ || c === 0x21 /* '!' */ ) { continue; } if ( isComment && recipeCondition === undefined ) { continue; }
if ( recipeName === undefined ) { if ( recipeName === undefined ) {
recipeName = line; recipeName = line;
recipeCondition = undefined; recipeCondition = undefined;
@ -136,7 +138,7 @@
if ( recipeRuleset.length !== 0 ) { if ( recipeRuleset.length !== 0 ) {
recipeRuleset += '\n'; recipeRuleset += '\n';
} }
recipeRuleset += toASCII(line); recipeRuleset += isComment ? line : toASCII(line);
} }
}; };
@ -163,7 +165,9 @@
let tMatrix = µm.tMatrix; let tMatrix = µm.tMatrix;
let pMatrix = µm.pMatrix; let pMatrix = µm.pMatrix;
let mustPersist = false; let mustPersist = false;
let reComment = /^[!#]/;
for ( let rule of details.ruleset.split('\n') ) { for ( let rule of details.ruleset.split('\n') ) {
if ( reComment.test(rule) ) { continue; }
let parts = rule.split(/\s+/); let parts = rule.split(/\s+/);
if ( parts.length < 2 ) { continue; } if ( parts.length < 2 ) { continue; }
let f0 = parts[0]; let f0 = parts[0];
@ -227,10 +231,13 @@
api.statuses = function(details) { api.statuses = function(details) {
let pMatrix = µMatrix.pMatrix, let pMatrix = µMatrix.pMatrix,
tMatrix = µMatrix.tMatrix; tMatrix = µMatrix.tMatrix;
let reComment = /^[!#]/;
for ( let recipe of details.recipes ) { for ( let recipe of details.recipes ) {
let ruleIter = new µMatrix.LineIterator(recipe.ruleset); let ruleIter = new µMatrix.LineIterator(recipe.ruleset);
while ( ruleIter.eot() === false ) { while ( ruleIter.eot() === false ) {
let parts = ruleIter.next().split(/\s+/); let rule = ruleIter.next();
if ( reComment.test(rule) ) { continue; }
let parts = rule.split(/\s+/);
if ( if (
recipe.mustCommit !== true && recipe.mustCommit !== true &&
evaluateRuleParts(pMatrix, details.scope, parts) evaluateRuleParts(pMatrix, details.scope, parts)

Loading…
Cancel
Save