fix(graphite): fixed minor graphite lexer issue when nodes begin with octal syntax and end with dash identifier, fixes #6049#

This commit is contained in:
Torkel Ödegaard
2016-09-21 20:04:09 +02:00
parent 9e26a4cfcb
commit d65fbcbb42
4 changed files with 239 additions and 236 deletions

View File

@@ -2,7 +2,7 @@
<div ng-repeat="variable in ctrl.variables" ng-hide="variable.hide === 2" class="submenu-item gf-form-inline"> <div ng-repeat="variable in ctrl.variables" ng-hide="variable.hide === 2" class="submenu-item gf-form-inline">
<div class="gf-form"> <div class="gf-form">
<label class="gf-form-label template-variable" ng-hide="variable.hide === 1"> <label class="gf-form-label template-variable" ng-hide="variable.hide === 1">
{{variable.label || variable.name}}: {{variable.label || variable.name}}
</label> </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> <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> </div>

View File

@@ -134,13 +134,7 @@ for (var i = 0; i < 128; i++) {
i >= 97 && i <= 122; // a-z i >= 97 && i <= 122; // a-z
} }
var identifierPartTable = []; var identifierPartTable = identifierStartTable;
for (var i2 = 0; i2 < 128; i2++) {
identifierPartTable[i2] =
identifierStartTable[i2] || // $, _, A-Z, a-z
i2 >= 48 && i2 <= 57; // 0-9
}
export function Lexer(expression) { export function Lexer(expression) {
this.input = expression; this.input = expression;
@@ -490,7 +484,11 @@ Lexer.prototype = {
if (isDecimalDigit(char)) { if (isDecimalDigit(char)) {
bad = true; 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; break;
} }
value += char; value += char;
@@ -508,7 +506,7 @@ Lexer.prototype = {
type: 'number', type: 'number',
value: value, value: value,
base: 8, base: 8,
isMalformed: false isMalformed: bad
}; };
} }

View File

@@ -100,10 +100,7 @@ Parser.prototype = {
}, },
metricExpression: function() { metricExpression: function() {
if (!this.match('templateStart') && if (!this.match('templateStart') && !this.match('identifier') && !this.match('number') && !this.match('{')) {
!this.match('identifier') &&
!this.match('number') &&
!this.match('{')) {
return null; return null;
} }

View File

@@ -62,6 +62,14 @@ describe('when lexing graphite expression', function() {
expect(tokens[4].type).to.be('identifier'); 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() { it('should tokenize func call with numbered metric and number arg', function() {
var lexer = new Lexer("scale(metric.10, 15)"); var lexer = new Lexer("scale(metric.10, 15)");
var tokens = lexer.tokenize(); var tokens = lexer.tokenize();