Commit 5617f10
committed
Properly escape filenames in #line directives
In some cases, backslashes in a filenames were already escaped when
emitting a #line directive, but sometimes no escaping happened. In any
case, quotes in a filename should also be escaped.
This commit introduces a helper function `QuoteCppString()` to handle
quoting and escaping strings in a generic way. This new helper function
is used in the code itself, but not in testcases yet.
Note that ctags does not quite properly handle special characters and
escaping in filenames. When parsing line markers, it just ignores
escapes, so any escapes from the #line marker will be present in the
ctags output as well. Before this commit, they would be copied
unmodified into the #line directives generated from the ctags filenames. Now that these line directives have escaping applied, the filenames read from ctags need to be unescaped, to prevent double escapes. This
unescaping already happened in CollectCTagsFromSketchFiles, but is now
moved to parseTag where it is more appropriate and applies to all users.
Since ctags does not handle escapes in line markers, it cuts the
filename off at the first double quote. If a filename contains a double
quote, the filename as output by ctags will be cut off before it,
leaving the escaping \ at the end. Before this commit, this trailing \
would be output directly into the generated #line marker, which confused
gcc and made the build fail. With this commit, this trailing \ is
escaped itself, making the output syntactically valid, so the build now
works with double quotes in a filename. However, due to this filename
cut off, arduino-builder will no longer generate prototypes for
functions in files that have a double quote in them (since it can no
longer detect them as sketch functions), so double quotes (and probably
tabs too) in filenames are still not completely supported yet.
Signed-off-by: Matthijs Kooijman <matthijs@stdin.nl>1 parent 6183f3b commit 5617f10
File tree
6 files changed
+37
-8
lines changed- src/arduino.cc/builder
- ctags
- test
- utils
6 files changed
+37
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
36 | 35 | | |
37 | 36 | | |
38 | 37 | | |
| |||
43 | 42 | | |
44 | 43 | | |
45 | 44 | | |
46 | | - | |
| 45 | + | |
47 | 46 | | |
48 | 47 | | |
49 | 48 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
229 | 229 | | |
230 | 230 | | |
231 | 231 | | |
232 | | - | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
233 | 240 | | |
234 | 241 | | |
235 | 242 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
90 | | - | |
| 91 | + | |
91 | 92 | | |
92 | 93 | | |
93 | 94 | | |
| |||
99 | 100 | | |
100 | 101 | | |
101 | 102 | | |
102 | | - | |
| 103 | + | |
103 | 104 | | |
104 | 105 | | |
105 | 106 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | | - | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
| 76 | + | |
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
407 | 407 | | |
408 | 408 | | |
409 | 409 | | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
0 commit comments