Comparing version
@@ -6,9 +6,11 @@ # Changelog | ||
As this project is pre 1.0, breaking changes may happen for minor version | ||
bumps. A breaking change will get clearly notified in this log. | ||
## [v1.0.0](https://github.com/stellar/js-xdr/compare/v0.0.12...v1.0.0) | ||
## [unreleased](https://github.com/stellar/js-xdr/compare/v0.0.11...master) | ||
### Changed | ||
- Strings are now encoded/decoded as utf-8 | ||
## [v0.0.12](https://github.com/stellar/js-xdr/compare/v0.0.11...v0.0.12) | ||
### Changed | ||
- bugfix: Hyper.fromString() no longer silently accepts strings with decimal points | ||
- bugfix: UnsignedHyper.fromString() no longer silently accepts strings with decimal points |
@@ -43,3 +43,3 @@ "use strict"; | ||
io.slice(padding); //consume padding | ||
return result.buffer().toString("ascii"); | ||
return result.buffer().toString("utf8"); | ||
} | ||
@@ -56,5 +56,5 @@ }, | ||
} | ||
var buffer = new Buffer(value, "ascii"); | ||
var buffer = new Buffer(value, "utf8"); | ||
Int.write(value.length, io); | ||
Int.write(buffer.length, io); | ||
io.writeBufferPadded(buffer); | ||
@@ -65,3 +65,7 @@ } | ||
value: function isValid(value) { | ||
return isString(value) && value.length <= this._maxLength; | ||
if (!isString(value)) { | ||
return false; | ||
} | ||
var buffer = new Buffer(value, "utf8"); | ||
return buffer.length <= this._maxLength; | ||
} | ||
@@ -68,0 +72,0 @@ } |
{ | ||
"name": "js-xdr", | ||
"version": "0.0.12", | ||
"version": "1.0.0", | ||
"description": "Read/write XDR encoded data structures (RFC 4506)", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -24,3 +24,3 @@ import { Int } from "./int"; | ||
io.slice(padding); //consume padding | ||
return result.buffer().toString('ascii'); | ||
return result.buffer().toString('utf8'); | ||
} | ||
@@ -38,5 +38,5 @@ | ||
} | ||
let buffer = new Buffer(value, 'ascii'); | ||
let buffer = new Buffer(value, 'utf8'); | ||
Int.write(value.length, io); | ||
Int.write(buffer.length, io); | ||
io.writeBufferPadded(buffer); | ||
@@ -46,6 +46,10 @@ } | ||
isValid(value) { | ||
return isString(value) && value.length <= this._maxLength; | ||
if (!isString(value)) { | ||
return false; | ||
} | ||
let buffer = new Buffer(value, 'utf8'); | ||
return buffer.length <= this._maxLength; | ||
} | ||
} | ||
includeIoMixin(String.prototype); | ||
includeIoMixin(String.prototype); |
import { Cursor } from "../../src/cursor"; | ||
import { cursorToArray } from "../support/io-helpers"; | ||
let subject = new XDR.String(2); | ||
let subject = new XDR.String(4); | ||
@@ -11,2 +11,3 @@ describe('String#read', function() { | ||
expect(read([0x00,0x00,0x00,0x01,0x41,0x00,0x00,0x00])).to.eql("A"); | ||
expect(read([0x00,0x00,0x00,0x03,0xe4,0xb8,0x89,0x00])).to.eql("三"); | ||
expect(read([0x00,0x00,0x00,0x02,0x41,0x41,0x00,0x00])).to.eql("AA"); | ||
@@ -16,3 +17,3 @@ }); | ||
it("throws a read error when the encoded length is greater than the allowed max", function() { | ||
expect(() => read([0x00,0x00,0x00,0x03])).to.throw(/read error/i); | ||
expect(() => read([0x00,0x00,0x00,0x05,0x41,0x41,0x41,0x41,0x41])).to.throw(/read error/i); | ||
}); | ||
@@ -30,2 +31,3 @@ | ||
expect(write("")).to.eql([0x00,0x00,0x00,0x00]); | ||
expect(write("三")).to.eql([0x00,0x00,0x00,0x03,0xe4,0xb8,0x89,0x00]); | ||
expect(write("A")).to.eql([0x00,0x00,0x00,0x01,0x41,0x00,0x00,0x00]); | ||
@@ -50,3 +52,3 @@ expect(write("AA")).to.eql([0x00,0x00,0x00,0x02,0x41,0x41,0x00,0x00]); | ||
it('returns false for strings that are too large', function() { | ||
expect(subject.isValid("aaa")).to.be.false; | ||
expect(subject.isValid("aaaaa")).to.be.false; | ||
}); | ||
@@ -53,0 +55,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
23412
3.15%0
-100%988912
-0.13%94
-8.74%