Skip to content

Commit cc5612e

Browse files
RohitSailyCommit Queue
authored andcommitted
Fix: False Positive "include_file_not_found"
See #59888 for an explanation of the bug this commit fixes. Incidentally, the bug prevents a "recursive_include_file" error from being reported when a file includes itself with a quoted "include" field value. This fix happens to also correct that so it is no longer the case. Introduce code to handle quotations delimiting an "include" field value. The code removes the quotes before the URI resolution is attempted. This will prevent quotations from being interpreted as a part of the URI to resolve. Also, add tests to verify these code changes fix the bug. [email protected], [email protected], [email protected] Bug: #59888 Change-Id: Idc921652bf356889142c6e38b0cdec5e66825d36 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/405180 Auto-Submit: Rohit Saily <[email protected]> Commit-Queue: Keerti Parthasarathy <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Keerti Parthasarathy <[email protected]>
1 parent 5ec1002 commit cc5612e

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

pkg/analyzer/lib/src/task/options.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ List<AnalysisError> analyzeAnalysisOptions(
9494
var includeSpan = includeNode.span;
9595
initialIncludeSpan ??= includeSpan;
9696
var includeUri = includeSpan.text;
97+
var (first, last) = (
98+
includeUri.codeUnits.firstOrNull,
99+
includeUri.codeUnits.lastOrNull);
100+
if ((first == 0x0022 || first == 0x0027) && first == last) {
101+
// The URI begins and ends with either a double quote or single quote
102+
// i.e. the value of the "include" field is quoted.
103+
includeUri = includeUri.substring(1, includeUri.length - 1);
104+
}
97105

98106
var includedSource = sourceFactory.resolveUri(source, includeUri);
99107
if (includedSource == initialSource) {

pkg/analyzer/test/src/diagnostics/analysis_options/include_file_not_found_test.dart

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,46 @@ main() {
1515

1616
@reflectiveTest
1717
class IncludeFileNotFoundTest extends AbstractAnalysisOptionsTest {
18-
void test_notFound() {
18+
void test_notFound_existent_doubleQuoted() {
19+
assertErrorsInCode('''
20+
include: "./analysis_options.yaml"
21+
''', [
22+
error(AnalysisOptionsWarningCode.RECURSIVE_INCLUDE_FILE, 9, 25)
23+
]);
24+
}
25+
26+
void test_notFound_existent_notQuoted() {
27+
assertErrorsInCode('''
28+
include: ./analysis_options.yaml
29+
''', [
30+
error(AnalysisOptionsWarningCode.RECURSIVE_INCLUDE_FILE, 9, 23)
31+
]);
32+
}
33+
34+
void test_notFound_existent_singleQuoted() {
35+
assertErrorsInCode('''
36+
include: './analysis_options.yaml'
37+
''', [
38+
error(AnalysisOptionsWarningCode.RECURSIVE_INCLUDE_FILE, 9, 25)
39+
]);
40+
}
41+
42+
void test_notFound_nonexistent_doubleQuoted() {
43+
assertErrorsInCode('''
44+
# We don't depend on pedantic, but we should consider adding it.
45+
include: "package:pedantic/analysis_options.yaml"
46+
''', [
47+
error(
48+
AnalysisOptionsWarningCode.INCLUDE_FILE_NOT_FOUND,
49+
74,
50+
40,
51+
text: "The include file 'package:pedantic/analysis_options.yaml'"
52+
" in '${convertPath('/analysis_options.yaml')}' can't be found when analyzing '/'.",
53+
)
54+
]);
55+
}
56+
57+
void test_notFound_nonexistent_notQuoted() {
1958
assertErrorsInCode('''
2059
# We don't depend on pedantic, but we should consider adding it.
2160
include: package:pedantic/analysis_options.yaml
@@ -29,4 +68,19 @@ include: package:pedantic/analysis_options.yaml
2968
)
3069
]);
3170
}
71+
72+
void test_notFound_nonexistent_singleQuoted() {
73+
assertErrorsInCode('''
74+
# We don't depend on pedantic, but we should consider adding it.
75+
include: 'package:pedantic/analysis_options.yaml'
76+
''', [
77+
error(
78+
AnalysisOptionsWarningCode.INCLUDE_FILE_NOT_FOUND,
79+
74,
80+
40,
81+
text: "The include file 'package:pedantic/analysis_options.yaml'"
82+
" in '${convertPath('/analysis_options.yaml')}' can't be found when analyzing '/'.",
83+
)
84+
]);
85+
}
3286
}

0 commit comments

Comments
 (0)