tracker issue : CF-4204029

select a category, or use search below
(searches all categories and all time range)
Title:

[ANeff] Bug for: Inconsistencies between I/O tags and functions regarding write, append, and newline

| View in Tracker

Status/Resolution/Reason: Needs Review//HaveNewInfo

Reporter/Name(from Bugbase): Aaron N. / ()

Created: 02/17/2019

Components: File Management

Versions: 2016,2018

Failure Type: Incorrectly functioning

Found In Build/Fixed In Build: 2018.0.0.310739 /

Priority/Frequency: Normal / Most users will encounter

Locale/System: / Windows 10 64 bit

Vote Count: 0

*NOTE* This ticket is a blocker to CF-4203313, b/c Adobe suggests CF-4203313 should add parameters to FileWrite() while other inconsistencies exist. CF-4203313's fix should consider the following inconsistencies, which should be fixed too.

Issues, when using filePath (not fileObject) parameter:
1) fileWrite() matches cffile(action="write",addnewline=false), but fileWriteLine() throws exception; it should match cffile(action="write",addnewline=true)
2) fileAppend() incorrectly appends newline character; it should match cffile(action="append",addnewline=false)
3) fileAppendLine() doesn't exist; it should match cffile(action="append",addnewline=true)

Repro (see comments for Actual vs Expected result):

<!--- write w/o new line --->
<cfscript>
cffile(action="write", file=expandPath("./myfileA1.txt"), output="OverwriteMe", addnewline=false);
cffile(action="write", file=expandPath("./myfileA1.txt"), output="A1", addnewline=false);
writeOutput(fileRead(expandPath("./myfileA1.txt")));
/*
Actual and Expected Result:
-----------
A1
-----------
*/

fileWrite(expandPath("./myfileA2.txt"), "OverwriteMe");
fileWrite(expandPath("./myfileA2.txt"), "A2");
writeOutput(fileRead(expandPath("./myfileA2.txt")));
/*
Actual and Expected Result:
-----------
A2
-----------
*/
</cfscript>

<!--- write w/ new line --->
<cfscript>
cffile(action="write", file=expandPath("./myfileB1.txt"), output="OverwriteMe", addnewline=false);
cffile(action="write", file=expandPath("./myfileB1.txt"), output="B1", addnewline=true);
writeOutput(fileRead(expandPath("./myfileB1.txt")));
/*
Actual and Expected Result:
-----------
B1

-----------
*/

try {
  fileWrite(expandPath("./myfileB2.txt"), "OverwriteMe");
  fileWriteLine(expandPath("./myfileB2.txt"), "B2");
  writeOutput(fileRead(expandPath("./myfileB2.txt")));
}
catch(any e) {writeOutput(e.message);};
/*
Actual Result: exception "The File object must be created by calling FileOpen()."
Expected Result:
-----------
B2

-----------
*/
</cfscript>

<!--- append w/o new line --->
<cfscript>
cffile(action="write", file=expandPath("./myfileC1.txt"), output="AppendToMe", addnewline=false);
cffile(action="append", file=expandPath("./myfileC1.txt"), output="C1", addnewline=false);
writeOutput(fileRead(expandPath("./myfileC1.txt")));
/*
Actual and Expected Result:
-----------
AppendToMeC1
-----------
*/

fileWrite(expandPath("./myfileC2.txt"), "AppendToMe");
fileAppend(expandPath("./myfileC2.txt"), "C2", "utf8");//Issues: 1) charset should be optional and 2) it shouldn't add new line. Since fileAppend() is undocumented, these can still be fixed.
writeOutput(fileRead(expandPath("./myfileC2.txt")));
/*
Actual Result:
-----------
AppendToMeC2

-----------
Expected Result:
-----------
AppendToMeC2
-----------
*/
</cfscript>

<!--- append w/ new line --->
<cfscript>
cffile(action="write", file=expandPath("./myfileD1.txt"), output="AppendToMe", addnewline=false);
cffile(action="append", file=expandPath("./myfileD1.txt"), output="D1", addnewline=true);
writeOutput(fileRead(expandPath("./myfileD1.txt")));
/*
Actual and Expected Result:
-----------
AppendToMeD1

-----------
*/

try {
  fileWrite(expandPath("./myfileD2.txt"), "AppendToMe");
  fileAppendLine(expandPath("./myfileD2.txt"), "D2");//Issue: FileAppendLine() does not exist
  writeOutput(fileRead(expandPath("./myfileD2.txt")));
}
catch(any e) {writeOutput(e.message);}
/*
Actual Result: exception "Variable FILEAPPENDLINE is undefined."
-----------
Expected Result:
-----------
AppendToMeD2

-----------
*/
</cfscript>

Attachments:

Comments:

Hi Adobe, Basically, if additional <cffile> attributes are added as parameters to FileWrite(), they'd need added to FileWriteLine(), FileAppend() and FileAppendLine() where relevant. This ticket reveals an unclear direction in the planning of CF8's I/O functions. I wasn't involved in Prereleases until CF8.0.1, so there's my excuse ;) Thanks!, -Aaron
Comment by Aaron N.
30288 | February 17, 2019 05:08:43 AM GMT
Hi Aaron,  1) fileWrite() matches cffile(action="write",addnewline=false), but fileWriteLine() throws exception; it should match cffile(action="write",addnewline=true) - FileWriteLine() doesn't have an argument to specify printing on a new Line as it expects it by default that every text that needs to be appended on the newline only. 2) fileAppend() incorrectly appends newline character; it should match cffile(action="append",addnewline=false) - user can disable can set newline by setting attribute addnewline as false.  Fix will be available in the upcoming update. Syntax : Fileappend(file,data,charset, addnewline). 3) fileAppendLine() doesn't exist; it should match cffile(action="append",addnewline=true) -  As of now , we are not thinking of fileAppendLine() as addnewline attribute can cater to this solution.  4)fileAppend(expandPath("./myfileC2.txt"), "C2", "utf8");//Issues: 1) charset should be optional and 2) it shouldn't add new line. Since fileAppend() is undocumented, these can still be fixed. * charset will be optional in the future release  * fileAppend() will be documented      Thanks, Mukesh  
Comment by Mukesh K.
30634 | March 12, 2019 07:47:16 AM GMT
Hi Aaron, Did you get a chance to look at my previous comment?    Thanks, Mukesh
Comment by Mukesh K.
30669 | April 30, 2019 09:32:47 AM GMT
Hi Mukesh, Thank you very much for the discussion. *Technically*, your idea works. However, I have another concern.. IMO, the CF language is not predictable if: 1) When _writing_, we use *separate functions* (FileWrite() vs FileWriteLine()) to toggle the addnewline behavior. 2) When _appending_, we use single function but *separate parameter value* (addnewline="true vs false") to toggle the addnewline behavior. 3) In FileWrite(), the missing addnewline parameter defaults to false 4) In FileAppend(), the proposed addnewline parameter defaults to true If I may, I'd like to propose a couple options for consideration: Option 1 (preferred): A) FileWrite(file, data[, charset[, addnewline]])//addnewline default is false B) FileAppend(file, data[, charset[, addnewline]])//addnewline default is false* * Since FileAppend() is undocumented, its addnewline default could be false. FileWriteLine() could eventually be deprecated. -or- Option 2: A) FileWrite(file, data[, charset]) B) FileWriteLine(file, data) C) FileAppend(file, data[, charset])//does not addnewline D) FileAppendLine(file, data) Thoughts? Thanks!, -Aaron
Comment by Aaron N.
30698 | May 09, 2019 12:27:39 AM GMT
Perhaps I should file a separate bug for: `fileWriteLine(filepath, data)` throws "The File object must be created by calling FileOpen()."? Thanks!, -Aaron
Comment by Aaron N.
30699 | May 09, 2019 12:29:46 AM GMT
Hi Adobe, Please ensure FileWrite() and FileAppend() take the same parameters and defaults, just as <cffile action="write"> and <cffile action="append"> take the same attributes and defaults. Related ticket: CF-4203313 Thanks!, -Aaron
Comment by Aaron N.
30700 | May 09, 2019 12:39:17 AM GMT
I realize addnewline defaults to *true* in <cffile action="write"> and <cffile action="append">, but backward-compat says <cffile>/FileWrite/FileAppend cannot have matching addnewline default.
Comment by Aaron N.
30701 | May 09, 2019 12:53:17 AM GMT