Commit d65fbcbb by Torkel Ödegaard

fix(graphite): fixed minor graphite lexer issue when nodes begin with octal…

fix(graphite): fixed minor graphite lexer issue when nodes begin with octal syntax and end with dash identifier, fixes #6049#
parent 9e26a4cf
......@@ -2,7 +2,7 @@
<div ng-repeat="variable in ctrl.variables" ng-hide="variable.hide === 2" class="submenu-item gf-form-inline">
<div class="gf-form">
<label class="gf-form-label template-variable" ng-hide="variable.hide === 1">
{{variable.label || variable.name}}:
{{variable.label || variable.name}}
</label>
<value-select-dropdown ng-if="variable.type !== 'adhoc'" variable="variable" on-updated="ctrl.variableUpdated(variable)" get-values-for-tag="ctrl.getValuesForTag(variable, tagKey)"></value-select-dropdown>
</div>
......
......@@ -134,13 +134,7 @@ for (var i = 0; i < 128; i++) {
i >= 97 && i <= 122; // a-z
}
var identifierPartTable = [];
for (var i2 = 0; i2 < 128; i2++) {
identifierPartTable[i2] =
identifierStartTable[i2] || // $, _, A-Z, a-z
i2 >= 48 && i2 <= 57; // 0-9
}
var identifierPartTable = identifierStartTable;
export function Lexer(expression) {
this.input = expression;
......@@ -490,7 +484,11 @@ Lexer.prototype = {
if (isDecimalDigit(char)) {
bad = true;
} else if (!isOctalDigit(char)) {
} if (!isOctalDigit(char)) {
// if the char is a non punctuator then its not a valid number
if (!this.isPunctuator(char)) {
return null;
}
break;
}
value += char;
......@@ -508,7 +506,7 @@ Lexer.prototype = {
type: 'number',
value: value,
base: 8,
isMalformed: false
isMalformed: bad
};
}
......@@ -674,5 +672,5 @@ Lexer.prototype = {
};
},
};
};
......@@ -100,10 +100,7 @@ Parser.prototype = {
},
metricExpression: function() {
if (!this.match('templateStart') &&
!this.match('identifier') &&
!this.match('number') &&
!this.match('{')) {
if (!this.match('templateStart') && !this.match('identifier') && !this.match('number') && !this.match('{')) {
return null;
}
......
......@@ -62,6 +62,14 @@ describe('when lexing graphite expression', function() {
expect(tokens[4].type).to.be('identifier');
});
it('should tokenize metric expression with segment that start with number', function() {
var lexer = new Lexer("metric.001-server");
var tokens = lexer.tokenize();
expect(tokens[0].type).to.be('identifier');
expect(tokens[2].type).to.be('identifier');
expect(tokens.length).to.be(3);
});
it('should tokenize func call with numbered metric and number arg', function() {
var lexer = new Lexer("scale(metric.10, 15)");
var tokens = lexer.tokenize();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment