diff --git a/lib/webofthings/wotutils.js b/lib/webofthings/wotutils.js index fcebadb..8b19bd7 100644 --- a/lib/webofthings/wotutils.js +++ b/lib/webofthings/wotutils.js @@ -18,7 +18,6 @@ const Ajv = require('ajv'); const url = require('url'); const fs = require('fs'); const path = require('path'); -const cldr = require('cldr'); function validateTd(td) { const TDSchema = @@ -40,21 +39,32 @@ function isOpInForms(op, forms) { .some(e=>e === op); } -function textDirection(lang) { - let dir = 'auto'; - try { - const ori = cldr.extractLayout(lang); - if (ori.characterOrder === 'left-to-right') { - dir = 'ltr' - } else if (ori.characterOrder === 'right-to-left') { - dir = 'rtl' - } - } catch (e) { - if (lang === "az-Arab") { - dir = 'rtl' - } +function textDirection(langid) { + // based on CLDR and other sources. + const rtlLangs = [ + "ar-AE","ar-BH","ar-DJ","ar-DZ","ar-EG","ar-EH","ar-ER","ar-IL","ar-IQ", + "ar-JO","ar-KM","ar-KW","ar-LB","ar-LY","ar-MA","ar-MR","ar-OM","ar-PS", + "ar-QA","ar-SA","ar-SD","ar-SO","ar-SS","ar-SY","ar-TD","ar-TN","ar-YE","ar", + "az-Arab", + "ckb-IR","ckb", + "fa-AF","fa", + "he", + "ks", + "lrc-IQ","lrc", + "mzn", + "pa-Arab", + "ps-PK","ps", + "sd", + "ug", + "ur-IN","ur", + "uz-Arab", + "yi", + ]; + if (langid === undefined || langid === "") { + return 'auto'; + } else { + return (rtlLangs.includes(langid) ? 'rtl' : 'ltr'); } - return dir; } function normalizeTd(td) { @@ -63,7 +73,9 @@ function normalizeTd(td) { function formconv(intr, f, affordance) { if (f.hasOwnProperty("href")) { - f.href = url.resolve(baseUrl, f.href); // decodeURIComponent(url.resolve(baseUrl, f.href)); + f.href = url.resolve(baseUrl, f.href) + .replace(/%7B/gi,'{') + .replace(/%7D/gi,'}'); } if (f.hasOwnProperty("security") && typeof f.security === 'string') { f.security = [f.security]; diff --git a/package.json b/package.json index 822ee68..39c3951 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,6 @@ "ajv": "6.12.0", "api-spec-converter": "2.11.0", "axios": "0.20.0", - "cldr": "5.5.4", "colors": "1.4.0", "csv-string": "3.1.8", "javascript-obfuscator": "0.28.1", diff --git a/templates/webofthings/node.js.mustache b/templates/webofthings/node.js.mustache index b84137b..fd639d6 100644 --- a/templates/webofthings/node.js.mustache +++ b/templates/webofthings/node.js.mustache @@ -431,7 +431,7 @@ module.exports = function (RED) { const urivars = prop.hasOwnProperty("uriVariables") ? msg.payload : {}; if (prop.uriVariables) { const ajv = new Ajv({allErrors: true}); - if (!ajv.validate(prop.uriVariables, urlvars)) { + if (!ajv.validate(prop.uriVariables, urivars)) { node.warn(`input schema validation error: ${ajv.errorsText()}`, msg); } }