Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions lib/webofthings/wotutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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) {
Expand All @@ -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];
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion templates/webofthings/node.js.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down