Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
cbbe362a
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
cbbe362a
编写于
8月 01, 2019
作者:
T
Tomáš Matoušek
提交者:
GitHub
8月 01, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
EE: Do not trim comments from expression preceding a quote (#37537)
* EE: Do not trim comments from expression preceding a quote
上级
043b7812
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
34 addition
and
2 deletion
+34
-2
src/ExpressionEvaluator/CSharp/Source/ResultProvider/CSharpFormatter.cs
...Evaluator/CSharp/Source/ResultProvider/CSharpFormatter.cs
+10
-1
src/ExpressionEvaluator/CSharp/Test/ResultProvider/FullNameTests.cs
...sionEvaluator/CSharp/Test/ResultProvider/FullNameTests.cs
+8
-0
src/ExpressionEvaluator/VisualBasic/Source/ResultProvider/VisualBasicFormatter.vb
...VisualBasic/Source/ResultProvider/VisualBasicFormatter.vb
+8
-1
src/ExpressionEvaluator/VisualBasic/Test/ResultProvider/FullNameTests.vb
...valuator/VisualBasic/Test/ResultProvider/FullNameTests.vb
+8
-0
未找到文件。
src/ExpressionEvaluator/CSharp/Source/ResultProvider/CSharpFormatter.cs
浏览文件 @
cbbe362a
...
...
@@ -34,6 +34,8 @@ internal override bool IsWhitespace(char c)
return
SyntaxFacts
.
IsWhitespace
(
c
);
}
// TODO: https://github.com/dotnet/roslyn/issues/37536
// This parsing is imprecise and may result in bad expressions.
internal
override
string
TrimAndGetFormatSpecifiers
(
string
expression
,
out
ReadOnlyCollection
<
string
>
formatSpecifiers
)
{
expression
=
RemoveComments
(
expression
);
...
...
@@ -47,7 +49,14 @@ private static string RemoveComments(string expression)
var
builder
=
pooledBuilder
.
Builder
;
var
inMultilineComment
=
false
;
int
length
=
expression
.
Length
;
for
(
int
i
=
0
;
i
<
length
;
i
++)
// Workaround for https://dev.azure.com/devdiv/DevDiv/_workitems/edit/847849
// Do not remove any comments that might be in a string.
// This won't work when there are quotes in the comment, but that's not that common.
int
lastQuote
=
expression
.
LastIndexOf
(
'"'
)
+
1
;
builder
.
Append
(
expression
,
0
,
lastQuote
);
for
(
int
i
=
lastQuote
;
i
<
length
;
i
++)
{
var
ch
=
expression
[
i
];
if
(
inMultilineComment
)
...
...
src/ExpressionEvaluator/CSharp/Test/ResultProvider/FullNameTests.cs
浏览文件 @
cbbe362a
...
...
@@ -108,6 +108,14 @@ class C
root
=
FormatResult
(
"/**/a// Comment"
,
value
);
Assert
.
Equal
(
"a.F"
,
GetChildren
(
root
).
Single
().
FullName
);
// See https://dev.azure.com/devdiv/DevDiv/_workitems/edit/847849
root
=
FormatResult
(
@"""a//b/*"" // c"
,
value
);
Assert
.
Equal
(
@"(""a//b/*"").F"
,
GetChildren
(
root
).
Single
().
FullName
);
// incorrect - see https://github.com/dotnet/roslyn/issues/37536
root
=
FormatResult
(
@"""a"" //""b"
,
value
);
Assert
.
Equal
(
@"(""a"" //""b).F"
,
GetChildren
(
root
).
Single
().
FullName
);
}
[
Fact
]
...
...
src/ExpressionEvaluator/VisualBasic/Source/ResultProvider/VisualBasicFormatter.vb
浏览文件 @
cbbe362a
...
...
@@ -39,6 +39,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExpressionEvaluator
Return
SyntaxFacts
.
IsWhitespace
(
c
)
End
Function
' TODO https://github.com/dotnet/roslyn/issues/37536
' This parsing is imprecise and may result in bad expressions.
Friend
Overrides
Function
TrimAndGetFormatSpecifiers
(
expression
As
String
,
ByRef
formatSpecifiers
As
ReadOnlyCollection
(
Of
String
))
As
String
expression
=
RemoveComments
(
expression
)
expression
=
RemoveFormatSpecifiers
(
expression
,
formatSpecifiers
)
...
...
@@ -46,7 +48,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExpressionEvaluator
End
Function
Private
Shared
Function
RemoveComments
(
expression
As
String
)
As
String
Dim
index
=
expression
.
IndexOf
(
"'"
c
)
' Workaround for https://dev.azure.com/devdiv/DevDiv/_workitems/edit/847849
' Do not remove any comments that might be in a string.
' This won't work when there are quotes in the comment, but that's not that common.
Dim
lastQuote
As
Integer
=
expression
.
LastIndexOf
(
"
""
"
c
)
+
1
Dim
index
=
expression
.
IndexOf
(
"'"
c
,
lastQuote
)
If
index
<
0
Then
Return
expression
End
If
...
...
src/ExpressionEvaluator/VisualBasic/Test/ResultProvider/FullNameTests.vb
浏览文件 @
cbbe362a
...
...
@@ -96,6 +96,14 @@ End Class
' The result provider should never see a value like this in the "real-world"
root
=
FormatResult
(
"''a' Comment"
,
value
)
Assert
.
Equal
(
".F"
,
GetChildren
(
root
).
Single
().
FullName
)
' See https://dev.azure.com/devdiv/DevDiv/_workitems/edit/847849
root
=
FormatResult
(
"
""
a'b
""
' c"
,
value
)
Assert
.
Equal
(
"(
""
a'b
""
).F"
,
GetChildren
(
root
).
Single
().
FullName
)
' incorrect - see https://github.com/dotnet/roslyn/issues/37536
root
=
FormatResult
(
"
""
a
""
'
""
b"
,
value
)
Assert
.
Equal
(
"(
""
a
""
'
""
b).F"
,
GetChildren
(
root
).
Single
().
FullName
)
End
Sub
<
Fact
>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录