File tree Expand file tree Collapse file tree 3 files changed +26
-3
lines changed
ReadableExpressions/Translations
ReadableExpressions.UnitTests Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,17 @@ public void ShouldTranslateAString()
27
27
translated . ShouldBe ( "\" hello!\" " ) ;
28
28
}
29
29
30
+ // See https://github.com/agileobjects/ReadableExpressions/issues/43
31
+ [ Fact ]
32
+ public void ShouldTranslateAStringWithANullTerminatingCharacter ( )
33
+ {
34
+ var stringConstant = Constant ( "hel\0 lo!" , typeof ( string ) ) ;
35
+
36
+ var translated = ToReadableString ( stringConstant ) ;
37
+
38
+ translated . ShouldBe ( @"""hel\0lo!""" ) ;
39
+ }
40
+
30
41
[ Fact ]
31
42
public void ShouldTranslateABoolean ( )
32
43
{
Original file line number Diff line number Diff line change @@ -101,5 +101,16 @@ public void ShouldMaintainNumericOperandParentheses()
101
101
102
102
translated . ShouldBe ( "((i - j) / k) + \" Maths!\" " ) ;
103
103
}
104
+
105
+ // See https://github.com/agileobjects/ReadableExpressions/issues/43
106
+ [ Fact ]
107
+ public void ShouldChandleANullTerminatingCharacter ( )
108
+ {
109
+ var concat = CreateLambda ( ( string str1 , string str2 ) => str1 + '\0 ' + str2 ) ;
110
+
111
+ var translated = ToReadableString ( concat . Body ) ;
112
+
113
+ translated . ShouldBe ( "str1 + '\\ 0' + str2" ) ;
114
+ }
104
115
}
105
116
}
Original file line number Diff line number Diff line change @@ -74,8 +74,9 @@ private static bool TryTranslateFromTypeCode(
74
74
return true ;
75
75
76
76
case NetStandardTypeCode . Char :
77
- translation = new TranslationWrapper ( FixedValueTranslation ( constant ) ) . WrappedWith ( "'" , "'" ) ;
78
-
77
+ var character = ( char ) constant . Value ;
78
+ var value = character == '\0 ' ? Expression . Constant ( @"\0" ) : constant ;
79
+ translation = new TranslationWrapper ( FixedValueTranslation ( value ) ) . WrappedWith ( "'" , "'" ) ;
79
80
return true ;
80
81
81
82
case NetStandardTypeCode . DateTime :
@@ -123,7 +124,7 @@ private static bool TryTranslateFromTypeCode(
123
124
return true ;
124
125
125
126
case NetStandardTypeCode . String :
126
- var stringValue = ( string ) constant . Value ;
127
+ var stringValue = ( ( string ) constant . Value ) . Replace ( " \0 " , @"\0" ) ;
127
128
128
129
if ( stringValue . IsComment ( ) )
129
130
{
You can’t perform that action at this time.
0 commit comments