Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.
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
15 changes: 13 additions & 2 deletions packages/lu/src/parser/lufile/entitySection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const EntitySectionContext = require('./generated/LUFileParser').LUFileParser.En
const DiagnosticSeverity = require('./diagnostic').DiagnosticSeverity;
const BuildDiagnostic = require('./diagnostic').BuildDiagnostic;
const LUSectionTypes = require('./../utils/enums/lusectiontypes');
const InvalidCharsInIntentOrEntityName = require('./../utils/enums/invalidchars').InvalidCharsInIntentOrEntityName;

class EntitySection {
/**
Expand All @@ -19,13 +20,23 @@ class EntitySection {
}

ExtractName(parseTree) {
let entityName;
if (parseTree.entityDefinition().entityLine().entityName()) {
return parseTree.entityDefinition().entityLine().entityName().getText().trim();
entityName = parseTree.entityDefinition().entityLine().entityName().getText().trim();
} else {
this.Errors.push(BuildDiagnostic({
message: "Invalid entity line, did you miss entity name after $",
context: parseTree.entityDefinition().entityLine()
}))
}));
}

if (entityName && InvalidCharsInIntentOrEntityName.some(x => entityName.includes(x))) {
this.Errors.push(BuildDiagnostic({
message: `Invalid entity line, entity name ${entityName} cannot contain any of the following characters: [<, >, *, %, &, :, \\, $]`,
context: parseTree.newEntityDefinition().newEntityLine()
}));
} else {
return entityName;
}
}

Expand Down
15 changes: 13 additions & 2 deletions packages/lu/src/parser/lufile/newEntitySection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const NewEntitySectionContext = require('./generated/LUFileParser').LUFileParser
const DiagnosticSeverity = require('./diagnostic').DiagnosticSeverity;
const BuildDiagnostic = require('./diagnostic').BuildDiagnostic;
const LUSectionTypes = require('./../utils/enums/lusectiontypes');
const InvalidCharsInIntentOrEntityName = require('./../utils/enums/invalidchars').InvalidCharsInIntentOrEntityName;

class NewEntitySection {
/**
Expand All @@ -23,16 +24,26 @@ class NewEntitySection {
}

ExtractName(parseTree) {
let entityName
if (parseTree.newEntityDefinition().newEntityLine().newEntityName()) {
return parseTree.newEntityDefinition().newEntityLine().newEntityName().getText().trim();
entityName = parseTree.newEntityDefinition().newEntityLine().newEntityName().getText().trim();
} else if (parseTree.newEntityDefinition().newEntityLine().newEntityNameWithWS()) {
return parseTree.newEntityDefinition().newEntityLine().newEntityNameWithWS().getText().trim();
entityName = parseTree.newEntityDefinition().newEntityLine().newEntityNameWithWS().getText().trim();
} else {
this.Errors.push(BuildDiagnostic({
message: "Invalid entity line, did you miss entity name after @",
context: parseTree.newEntityDefinition().newEntityLine()
}))
}

if (entityName && InvalidCharsInIntentOrEntityName.some(x => entityName.includes(x))) {
this.Errors.push(BuildDiagnostic({
message: `Invalid entity line, entity name ${entityName} cannot contain any of the following characters: [<, >, *, %, &, :, \\, $]`,
context: parseTree.newEntityDefinition().newEntityLine()
}));
} else {
return entityName;
}
}

ExtractType(parseTree) {
Expand Down
7 changes: 7 additions & 0 deletions packages/lu/src/parser/lufile/visitor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const lp = require('./generated/LUFileParser').LUFileParser;
const LUISObjNameEnum = require('./../utils/enums/luisobjenum');
const InvalidCharsInIntentOrEntityName = require('./../utils/enums/invalidchars').InvalidCharsInIntentOrEntityName;

class Visitor {
/**
Expand Down Expand Up @@ -38,6 +39,12 @@ class Visitor {
static recurselyResolveTokenizedUtterance(tokUtt, entities, errorMsgs, srcUtterance) {
for (const item of tokUtt) {
if (item === Object(item)) {
let entityName = item.entityName.trim()
if (entityName && InvalidCharsInIntentOrEntityName.some(x => entityName.includes(x))) {
errorMsgs.push(`Invalid utterance line, entity name ${entityName} cannot contain any of the following characters: [<, >, *, %, &, :, \\, $]`);
continue;
}

if (item.entityValue === undefined) {
// we have a pattern.any entity
const patternStr = item.role ? `{${item.entityName}:${item.role}}` : `{${item.entityName}}`
Expand Down
8 changes: 8 additions & 0 deletions packages/lu/src/parser/utils/enums/invalidchars.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
// Invalid chars in intent or entity name
module.exports = {
InvalidCharsInIntentOrEntityName: ['<', '>', '*', '%', '&', ':', '\\', '$']
};
13 changes: 13 additions & 0 deletions packages/lu/test/commands/luis/convert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,19 @@ describe('luis:convert negative tests', () => {
})

})

it('luis:convert should show ERR message when entity name contains invalid char', (done) => {
loadLuFile('./../../fixtures/testcases/bad5.lu')
.then(res => {
LuisBuilder.fromLUAsync(res)
.then(res => done(res))
.catch(err => {
assert.isTrue(err.text.includes('[ERROR] line 2:0 - line 2:26: Invalid utterance line, entity name @addto*Property cannot contain any of the following characters: [<, >, *, %, &, :, \\, $]'))
assert.isTrue(err.text.includes('[ERROR] line 4:0 - line 4:20: Invalid entity line, entity name delete$Property cannot contain any of the following characters: [<, >, *, %, &, :, \\, $]'))
done()
})
})
})
})

describe('luis:convert new entity format', () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/lu/test/fixtures/testcases/bad5.lu
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# greeting
- hi {@addto*Property=foo}

@ ml delete$Property