存储在由 DXL 脚本填充的属性中的意外结果

Unexpected result stored in attribute populated by DXL script

我现在是一堆 dxl 脚本的维护者,我正在测试它们。

有问题的脚本将多个字符串格式化为缓冲区,然后再转换回字符串。然后将该字符串与另一个字符串连接起来,然后存储在一个属性中。代码如下(变量名称和函数参数的数量已被清理,仅供参考):

string formatForField(string s1, string s2){
    Buffer buff = create();

    buff += s1 
    buff += "\n";
    buff += s2;

    string formattedString = tempStringOf(buff);
    delete(buff);
    return formattedString;
}

void alterField(string inputString1, string inputString2){
    string formattedChange = formatForField(inputString1, inputString2);
    string oldValue = currentObject."Attribute Name";

    if (oldValue != "") {
        oldValue = oldValue "\n---\n";
    }

    string newValue = oldValue formattedChange;
    currentObject."Attribute Name" = newValue;
}

问题是,当前对象的值 "Attribute Name" 偶尔会在先前的值上附加 □,而不是预期的结果。

例如,如果 (current object)."Attribute Name 的值为 "Lorem Ipsum",并且在 运行 脚本之后,(current object)."Attribute Name 的预期值为:

Lorem Ipsum
---
inputString1
inputString2

那么偶尔,(current object)."Attribute Name的值实际上会是:

Lorem Ipsum
---
□

我无法在网上找到任何类似的报告问题,所以我在这里发帖。我不确定这里发生了什么,因为 99% 的时间脚本提供了预期的输出。有趣的是,如果属性包含 运行 脚本后的白色方块,运行 再次使用相同输入的脚本将产生预期的输出...

编辑:This image shows the white square I am on about, as it doesn't seem to show up in the live post view

额外编辑:经过进一步检查,我发现有时会包含额外的随机字符。 The right column is supposed to contain text, not the random characters it does contain.

请原谅我在这里说的很明显,但我不确定问题到底出在哪里。据我了解,alterField 具有以下特征。

预期输入是两个字符串。前提条件:两者都必须有值。 该函数检查属性 "Attribute Name" 是否已经有值。如果是这样,则应保留旧值并将两个字符串添加到旧值,并用破折号分隔。这两个字符串由回车连接 return.

因此,在启动以下脚本后

Object currentObject = first
currentObject."Attribute Name" = "good morning"
String partOne = "good"
String partTwo = "evening"
alterField (partOne, partTwo)
alterField (partOne, partTwo)
alterField (partOne, partTwo)

模块第一个对象的属性"Attribute Name"将具有以下内容:

good morning
---
good
evening
---
good
evening
---
good
evening

如果不满足前提条件且 partOne 为空 (""),partTwo 为 "evening",则在三次调用 alterField 之后属性将如下所示:

good morning
---

evening
---

evening
---

evening

问题是:你期望发生什么?

意识到错误。调用后buff被删除 tempStringOf 等被引用的内存被释放,导致奇怪。我犯了一个愚蠢的错误。