Skip to content

Commit 2a425c6

Browse files
chfritzchris-smith
authored andcommitted
Small bug fix for constants in on-the-fly message classes (#33) (#34)
Prior to this commit constant values like "1.0", i.e., floats that are integer, were not correctly treated in the md5sum calculation -- they were abbreviated to "1", causing incorrect md5sums. This commit fixes that by using the original string value for md5sum calculation (up to the start of a comment (for strings) or the first whitespace character for any other field type). - also fixing some wrong logic for null values
1 parent 9da1e9f commit 2a425c6

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

utils/messages.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,14 +341,27 @@ function extractFields(content, details, callback) {
341341

342342
if (equalIndex !== -1) {
343343
fieldName = field.substring(0, equalIndex).trim();
344+
// truncate comments and whitespace
344345
var constant = field.substring(equalIndex + 1, field.length).trim();
346+
var constantEnd = constant.length;
347+
var constantComment = constant.indexOf("#");
348+
if (constantComment >= 0) {
349+
if (fieldType != "string") {
350+
var firstWhitespace = constant.match(/\s/);
351+
if (firstWhitespace) {
352+
constantEnd = firstWhitespace.index;
353+
}
354+
} else {
355+
constantEnd = constantComment;
356+
}
357+
}
345358
var parsedConstant = fieldsUtil.parsePrimitive(fieldType, constant);
346359

347360
constants.push({
348361
name : fieldName
349362
, type : fieldType
350363
, value : parsedConstant
351-
, raw : constant
364+
, raw : constant.slice(0, constantEnd)
352365
, index : fields.length
353366
, messageType : null
354367
});
@@ -504,7 +517,9 @@ function buildMessageClass(details) {
504517
new (field.messageType)(values ? values[field.name] : undefined);
505518
} else {
506519
// simple value
507-
that[field.name] = values ? values[field.name] :
520+
that[field.name] =
521+
(values && typeof values[field.name] != "undefined") ?
522+
values[field.name] :
508523
(field.value || fieldsUtil.getDefaultValue(field.type));
509524
}
510525
});

0 commit comments

Comments
 (0)