Skip to content

Commit

Permalink
feat(ber encoding): Adds type to Ember.ParameterContents objects. All…
Browse files Browse the repository at this point in the history
…ows for explicitly setting Real ParameterContents types to enforce correct encoding.

Solves a problem where 1.0 and 1 can't be distringuished by Number.parseInteger(). This results in Real properties wrongly being encoded to Integers, which breaks the protocol.
  • Loading branch information
jesperstarkar committed May 3, 2018
1 parent 8d9e89e commit 153eed8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 9 additions & 1 deletion ber.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,15 @@ ExtendedWriter.prototype.writeReal = function(value, tag) {
}

ExtendedWriter.prototype.writeValue = function(value, tag) {
if(Number.isInteger(value)) {
// accepts Ember.ParameterContents for enforcing real types
if(typeof value === 'object' && value.type && value.type.key && value.type.key.length && typeof value.type.key === 'string') {
if(value.type.key === 'real') {
this.writeReal(value.value, tag);
return
}
}

if(Number.isInteger(value)) {
if (tag === undefined) {
tag = EMBER_INTEGER;
}
Expand Down
7 changes: 6 additions & 1 deletion ember.js
Original file line number Diff line number Diff line change
Expand Up @@ -2074,10 +2074,15 @@ var ParameterType = new Enum({
module.exports.ParameterAccess = ParameterAccess;
module.exports.ParameterType = ParameterType;

function ParameterContents(value) {
function ParameterContents(value, type) {
if(value !== undefined) {
this.value = value;
}
if(type !== undefined) {
if((type = ParameterType.get(type)) !== undefined){
this.type = type
}
}
};

module.exports.ParameterContents = ParameterContents;
Expand Down

0 comments on commit 153eed8

Please sign in to comment.