File tree Expand file tree Collapse file tree 3 files changed +38
-9
lines changed
src/DocumentFormat.OpenXml
test/DocumentFormat.OpenXml.Tests/ofapiTest Expand file tree Collapse file tree 3 files changed +38
-9
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
8
8
9
9
### Fixed
10
10
- Fixed bug where properties on ` OpenXmlCompositeElement ` instances could not be set to null to remove element (#850 )
11
+ - Fixed ` OpenXmlElement.RawOuterXml ` to properly set null values without throwing (#818 )
11
12
- Allow rewriting of all malformed URIs regardless of target value (#835 )
12
13
13
14
## Version 2.12.0 - 2020-12-09
Original file line number Diff line number Diff line change @@ -154,15 +154,7 @@ internal string RawOuterXml
154
154
{
155
155
get => _rawOuterXml ;
156
156
157
- set
158
- {
159
- if ( string . IsNullOrEmpty ( value ) )
160
- {
161
- _rawOuterXml = string . Empty ;
162
- }
163
-
164
- _rawOuterXml = value ;
165
- }
157
+ set => _rawOuterXml = value ?? string . Empty ;
166
158
}
167
159
168
160
private Framework . Metadata . ElementState _state ;
Original file line number Diff line number Diff line change @@ -145,6 +145,42 @@ public void TestGetXPathIndex()
145
145
Assert . Equal ( 2 , target ) ;
146
146
}
147
147
148
+ /// <summary>
149
+ /// Tests if empty string is set when
150
+ /// null value is given to setter
151
+ /// </summary>
152
+ [ Fact ]
153
+ public void TestSetRawOuterXmlField_NullValueIsSet_FieldShouldNotBeNull ( )
154
+ {
155
+ var openXmlElement = new Document ( ) ;
156
+ openXmlElement . RawOuterXml = null ;
157
+ Assert . NotNull ( openXmlElement . RawOuterXml ) ;
158
+ }
159
+
160
+ /// <summary>
161
+ /// Tests if proper string value is set when
162
+ /// setter is invoked
163
+ /// </summary>
164
+ [ Fact ]
165
+ public void TestSetRawOuterXmlField_ValueIsSet_FieldShouldContainSetValue ( )
166
+ {
167
+ var openXmlElement = new Document ( ) ;
168
+ var testValue = "Some proper value" ;
169
+ openXmlElement . RawOuterXml = testValue ;
170
+ Assert . Equal ( testValue , openXmlElement . RawOuterXml ) ;
171
+ }
172
+
173
+ /// <summary>
174
+ /// Tests if field is empty when empty string is set
175
+ /// </summary>
176
+ [ Fact ]
177
+ public void TestSetRawOuterXmlField_SetValueIsEmpty_FieldShouldBeEmpty ( )
178
+ {
179
+ var openXmlElement = new Document ( ) ;
180
+ openXmlElement . RawOuterXml = string . Empty ;
181
+ Assert . Equal ( string . Empty , openXmlElement . RawOuterXml ) ;
182
+ }
183
+
148
184
[ Fact ]
149
185
public void CanSetNullValue ( )
150
186
{
You can’t perform that action at this time.
0 commit comments