mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	Merge pull request #3659 from Steve-Mcl/backport-3624
fix buffer parse error message of evaluateNodeProperty (backports #3624 for v2.x)
This commit is contained in:
		@@ -641,7 +641,12 @@ function evaluateNodeProperty(value, type, node, msg, callback) {
 | 
			
		||||
        result = Date.now();
 | 
			
		||||
    } else if (type === 'bin') {
 | 
			
		||||
        var data = JSON.parse(value);
 | 
			
		||||
        result = Buffer.from(data);
 | 
			
		||||
        if (Array.isArray(data) || (typeof(data) === "string")) {
 | 
			
		||||
            result = Buffer.from(data);
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            throw createError("INVALID_BUFFER_DATA", "Not string or array");
 | 
			
		||||
        }
 | 
			
		||||
    } else if (type === 'msg' && msg) {
 | 
			
		||||
        try {
 | 
			
		||||
            result = getMessageProperty(msg,value);
 | 
			
		||||
 
 | 
			
		||||
@@ -388,6 +388,19 @@ describe("@node-red/util/util", function() {
 | 
			
		||||
            result[0].should.eql(1);
 | 
			
		||||
            result[1].should.eql(2);
 | 
			
		||||
        });
 | 
			
		||||
        it('throws an error if buffer data is not array or string', function (done) {
 | 
			
		||||
            try {
 | 
			
		||||
                var result = util.evaluateNodeProperty('12','bin');
 | 
			
		||||
                done("should throw an error");
 | 
			
		||||
            } catch (err) {
 | 
			
		||||
                if (err.code === "INVALID_BUFFER_DATA") {
 | 
			
		||||
                    done();
 | 
			
		||||
                }
 | 
			
		||||
                else {
 | 
			
		||||
                    done("should throw an error");
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
        it('returns msg property',function() {
 | 
			
		||||
            var result = util.evaluateNodeProperty('foo.bar','msg',{},{foo:{bar:"123"}});
 | 
			
		||||
            result.should.eql("123");
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user