Skip to content

Commit

Permalink
Merge pull request #56 from boschrexroth/bugfix/46-special-character-…
Browse files Browse the repository at this point in the history
…datalayer-path-failure

fix: #46 support addresses with special characters (e.g. '^' in 'mm/s…
  • Loading branch information
Sebastian Krauskopf committed Oct 16, 2022
2 parents a9fa284 + 178b41d commit 46ba062
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
7 changes: 6 additions & 1 deletion README.md
Expand Up @@ -71,6 +71,7 @@ Any use of the source code and related documents of this repository in applicati

## Changelog

```text
* 2020-09-29: 1.2.0 - Initial release with request node for ctrlX Data Layer.
* 2020-11-28: 1.2.2 - fix: msg.topic is not set to path if msg.topic is undefined.
* 2020-12-02: 1.2.3 - Only documentation and diagnosis improvements.
Expand Down Expand Up @@ -98,7 +99,11 @@ Any use of the source code and related documents of this repository in applicati
fix: remove an uncaught exception which was introduced with version 1.8.14 (Bug454078).
* 2022-04-26: 1.8.16 - fix: possible connection break on heavy load for commands: create, delete, write.
* 2022-05-05: 1.8.17 - feat: added support for IPv6.
* 2022-05-06: 1.8.18 - fix: possible node crash on browsing with bad credentials
* 2022-05-06: 1.8.18 - fix: possible node crash on browsing with bad credentials.
* 2022-10-16: 1.8.19 - fix: make IPv6 work on device.
- fix: support addresses with special characters (e.g. '^' in 'mm/s^2').
- docs: updated and extended the example flows.
```

## About

Expand Down
2 changes: 1 addition & 1 deletion lib/CtrlxDatalayerSubscription.js
Expand Up @@ -115,7 +115,7 @@ class CtrlxDatalayerSubscription extends EventEmitter {
// Arguments are given as query parameter.
// IPv6: We have to use IPv6 square brackets for valid url
let urlhostname = this._isIPv6 ? '[' + this._hostname + ']' : this._hostname;
let url = `https://${urlhostname}:${this._port}/automation/api/v2/events?nodes=${this._nodes}`;
let url = `https://${urlhostname}:${this._port}/automation/api/v2/events?nodes=` + encodeURIComponent(this._nodes.toString());
if (typeof this._publishIntervalMs !== 'undefined') {
url += `&publishIntervalMs=${this._publishIntervalMs}`;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-ctrlx-automation",
"version": "1.8.18",
"version": "1.8.19",
"description": "Node-RED nodes for ctrlX AUTOMATION",
"repository": {
"type": "git",
Expand Down
30 changes: 30 additions & 0 deletions test/CtrlxCore.events.test.js
Expand Up @@ -118,6 +118,36 @@ describe('CtrlxCoreDataLayerEvents', function() {
});


it('should subscribe to a single node with escaped characters', function(done) {
this.timeout(5000);
let ctrlx = new CtrlxCore(getHostname(), getUsername(), getPassword());

ctrlx.logIn().then(() => {
// Create the subscription
return ctrlx.datalayerSubscribe(['motion/axs/Axis_X/state/values/actual/acc/cm-per-s^2']);
}).then((subscription) => {
// Check and count the updates
expect(subscription).to.exist;
subscription.on('update', (data) => {

expect(data.node).to.be.a('string').eql('motion/axs/Axis_X/state/values/actual/acc/cm-per-s^2');
expect(data.timestamp).to.be.a('number');
expect(data.type).to.be.a('string').eql('double');
expect(data.value).to.be.a('number').eql(42);

const timestamp = CtrlxDatalayerSubscription.convertTimestamp2Date(data.timestamp);
const deltaTime = Math.abs(timestamp.valueOf() - Date.now());
expect(deltaTime).to.be.below(500);

subscription.close();
done();
});
})
.catch((err) => done(err))
.finally(() => ctrlx.logOut());

});


it('should subscribe to multiple nodes', async function() {
this.timeout(5000);
Expand Down
12 changes: 12 additions & 0 deletions test/helper/CtrlxMockupV2.js
Expand Up @@ -346,6 +346,14 @@ class CtrlxMockupV2 {
res.send();
return;
}

// URL characters (e.g. '^') must be encoded
if (req.url.includes("^")) {
res.statusCode = 400;
res.send();
return;
}

// @ts-ignore
let nodes = req.query.nodes.split(',');

Expand Down Expand Up @@ -380,6 +388,10 @@ class CtrlxMockupV2 {
data.value = Math.round(Math.random() * 4096);
data.type = 'int16';
break;
case 'motion/axs/Axis_X/state/values/actual/acc/cm-per-s^2':
data.value = 42;
data.type = 'double';
break;
case 'test/broken/connection/i':
data.value = id;
data.type = 'int16';
Expand Down

0 comments on commit 46ba062

Please sign in to comment.