Skip to content

Build your personal knowledge base with Trilium Notes

validate/clean inverse relation name in promoted attr definition

zadam79b8d9102578
diff --git a/src/public/app/widgets/attribute_widgets/attribute_detail.js b/src/public/app/widgets/attribute_widgets/attribute_detail.js
index 1860f4361d..ea8f68649a 100644
--- a/src/public/app/widgets/attribute_widgets/attribute_detail.js
+++ b/src/public/app/widgets/attribute_widgets/attribute_detail.js
@@ -626,7 +626,9 @@ export default class AttributeDetailWidget extends NoteContextAwareWidget {
props.push('precision=' + this.$inputNumberPrecision.val());
}
} else if (this.attrType === 'relation-definition' && this.$inputInverseRelation.val().trim().length > 0) {
- props.push("inverse=" + this.$inputInverseRelation.val());
+ const inverseRelationName = this.$inputInverseRelation.val();
+
+ props.push("inverse=" + utils.filterAttributeName(inverseRelationName));
}
this.$rowNumberPrecision.toggle(
diff --git a/src/services/promoted_attribute_definition_parser.js b/src/services/promoted_attribute_definition_parser.js
index d7f611cb91..48856cab6a 100644
--- a/src/services/promoted_attribute_definition_parser.js
+++ b/src/services/promoted_attribute_definition_parser.js
@@ -20,7 +20,7 @@ function parse(value) {
else if (token.startsWith('inverse')) {
const chunks = token.split('=');
- defObj.inverseRelation = chunks[1];
+ defObj.inverseRelation = chunks[1].replace(/[^\p{L}\p{N}_:]/ug, "")
}
else {
console.log("Unrecognized attribute definition token:", token);
diff --git a/src/services/utils.js b/src/services/utils.js
index 2bcdc44e1a..4ff2027a12 100644
--- a/src/services/utils.js
+++ b/src/services/utils.js
@@ -298,6 +298,10 @@ function normalize(str) {
return removeDiacritic(str).toLowerCase();
}
+function filterAttributeName(name) {
+ return name.replace(/[^\p{L}\p{N}_:]/ug, "");
+}
+
module.exports = {
randomSecureToken,
randomString,
@@ -331,5 +335,6 @@ module.exports = {
timeLimit,
deferred,
removeDiacritic,
- normalize
+ normalize,
+ filterAttributeName
};