Skip to content

Commit

Permalink
Use quotes around field names that start with an integer (#293)
Browse files Browse the repository at this point in the history
* Use quotes around fields that start with integer

* Adjust regex to only recognize fields starting with integer

* Add unit tests for quotation-wrapping

---------

Co-authored-by: Zech Andersen <zech.andersen@swisssalary.ch>
  • Loading branch information
zeande and Zech Andersen committed Nov 27, 2023
1 parent ecdcbd2 commit 3cea7fb
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/StringFunctions.ts
Expand Up @@ -18,7 +18,7 @@ export class StringFunctions {
return str;
}

if (/[^a-zA-Z0-9_]/.test(str) || DynamicsNAV.isKeyWord(str)) {
if (/[^a-zA-Z0-9_]/.test(str) || /^[0-9]/.test(str) || DynamicsNAV.isKeyWord(str)) {
return "\"" + str + "\"";
} else {
return str;
Expand Down
21 changes: 21 additions & 0 deletions src/test/suite/NAVObject.PrefexAndSuffix.test.ts
Expand Up @@ -268,6 +268,27 @@ suite("NAVObject ObjectNamePrefix Tests", () => {
assert.strictEqual(field.name.startsWith(testSettings[Settings.ObjectNamePrefix]), false) //does not start with prefix
})
});
test("Page - add quotations to fields/actions", () => {
let testSettings = Settings.GetConfigSettings(null)
testSettings[Settings.ObjectNamePrefix] = 'waldo';

let navTestObject = NAVTestObjectLibrary.getPageWithIntegerPrefixedNames();
let navObject = new NAVObject(navTestObject.ObjectText, testSettings, navTestObject.ObjectFileName)

// Non integer-prefixed actions and fields are not contained in double-quotes
assert.strictEqual(navObject.objectActions.find(a => a.name === 'Action1')
.fullActionTextFixed, " action(Action1)");

assert.strictEqual(navObject.pageFields.find(a => a.name === 'Field1')
.fullFieldTextFixed, "field(Field1; RandomSource)");

// Integer-prefixed actions and fields are contained in double-quotes
assert.strictEqual(navObject.objectActions.find(a => a.name === '2Action')
.fullActionTextFixed, " action(\"2Action\")");

assert.strictEqual(navObject.pageFields.find(a => a.name === '2Field')
.fullFieldTextFixed, "field(\"2Field\"; RandomSource)");
});
test("Pageextension - avoid setting double prefixes to actions", () => {
let testSettings = Settings.GetConfigSettings(null)
testSettings[Settings.ObjectNamePrefix] = 'waldo';
Expand Down
53 changes: 53 additions & 0 deletions src/test/suite/NAVTestObjectLibrary.ts
Expand Up @@ -898,6 +898,59 @@ export function getPageNoPrefixCorrectNameWithActions(): NAVTestObject {
return object;
}

export function getPageWithIntegerPrefixedNames(): NAVTestObject {
let object = new NAVTestObject;

object.ObjectFileName = 'FieldsWithIntegers.Page.al'
object.ObjectText = `page 50104 FieldsWithIntegers
{
PageType = Card;
SourceTable = test;
layout
{
area(content)
{
group(GroupName)
{
field(Field1; RandomSource)
{
ApplicationArea = All;
}
field(2Field; RandomSource)
{
ApplicationArea = All;
}
}
}
}
actions
{
area(processing)
{
action(Action1)
{
ApplicationArea = All;
trigger OnAction()
begin
end;
}
action(2Action)
{
ApplicationArea = All;
trigger OnAction()
begin
end;
}
}
}
}`
return object;
}

export function getObjectWithBracketsInName(): NAVTestObject {
let object = new NAVTestObject;

Expand Down

0 comments on commit 3cea7fb

Please sign in to comment.