Skip to content

Instantly share code, notes, and snippets.

@adamcameron
Last active January 2, 2016 05:09
Show Gist options
  • Save adamcameron/8255274 to your computer and use it in GitHub Desktop.
Save adamcameron/8255274 to your computer and use it in GitHub Desktop.
Demonstration of bug in CF10's file looping
cffileRead: [abcdefghijklmnopqrstuvwxy*()__+[]\{}|;':",./<>?]
cfloopRead: [abcdefghijklmnopqrstuvwxy*()__+[]\{}|;':",./<>?]
EQ: NO
compare: -1
len: cffileRead: 47; cfloopRead: 48
i char from cffileRead char from cfloopRead
1 a (97)  (65279)
2 b (98) a (97)
3 c (99) b (98)
4 d (100) c (99)
5 e (101) d (100)
6 f (102) e (101)
7 g (103) f (102)
8 h (104) g (103)
9 i (105) h (104)
10 j (106) i (105)
11 k (107) j (106)
12 l (108) k (107)
13 m (109) l (108)
14 n (110) m (109)
15 o (111) n (110)
16 p (112) o (111)
17 q (113) p (112)
18 r (114) q (113)
19 s (115) r (114)
20 t (116) s (115)
21 u (117) t (116)
22 v (118) u (117)
23 w (119) v (118)
24 x (120) w (119)
25 y (121) x (120)
26 * (42) y (121)
27 ( (40) * (42)
28 ) (41) ( (40)
29 _ (95) ) (41)
30 _ (95) _ (95)
31 + (43) _ (95)
32 [ (91) + (43)
33 ] (93) [ (91)
34 \ (92) ] (93)
35 { (123) \ (92)
36 } (125) { (123)
37 | (124) } (125)
38 ; (59) | (124)
39 ' (39) ; (59)
40 : (58) ' (39)
41 " (34) : (58)
42 , (44) " (34)
43 . (46) , (44)
44 / (47) . (46)
45 < (60) / (47)
46 > (62) < (60)
47 ? (63) > (62)
48 (0) ? (63)
<cfset folder = expandPath(".") & "\">
<cfset fileName = "test.txt">
<cfset filePath = folder & fileName>
<cffile action="read" file="#filePath#" variable="cffileRead" charset="UTF-8">
<cfloop index="cfloopRead" file="#filePath#" charset="UTF-8">
</cfloop>
<cfoutput>
<code>
cffileRead: [#cffileRead#]<br>
cfloopRead: [#cfloopRead#]<br>
</code>
<br>
EQ: #cffileRead EQ cfloopRead#<br>
compare: #compare(cffileRead,cfloopRead)#<br>
len: cffileRead: #len(cffileRead)#; cfloopRead: #len(cfloopRead)#<br>
<br>
<table border="1">
<thead>
<tr><th>i</th><th>char from cffileRead</th><th>char from cfloopRead</th></tr>
</thead>
<tbody>
<cfloop index="i" from="1" to="#max(len(cffileRead),len(cfloopRead))#">
<tr>
<td>#i#</td>
<td><cftry><cfset c = mid(cffileRead, i, 1)>#c# (#asc(c)#)<cfcatch>NOT SET</cfcatch></cftry></td>
<td><cftry><cfset c = mid(cfloopRead, i, 1)>#c# (#asc(c)#)<cfcatch>NOT SET</cfcatch></cftry></td>
</tr>
</cfloop>
</tbody>
</table>
</cfoutput>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment