<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:38:13 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CSHARP-930] If any of the keys in a Dictionary contains a null character serialization fails</title>
                <link>https://jira.mongodb.org/browse/CSHARP-930</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;I came across the following error when I tried to serialize one of our documents. We submit exception documents with our product. So the following document came from a security scan of some kind.. Anyways mongo blew up and we caught the exception. We have a few hundred reports of this. &lt;/p&gt;

&lt;p&gt;The value trying to be inserted is &quot;\u0000\&quot;&amp;gt;&amp;lt;script&amp;gt;alert(309)&amp;lt;/script&amp;gt;&quot;&lt;/p&gt;

&lt;p&gt;System.ArgumentException : Element names cannot contain nulls.&lt;br/&gt;
Parameter name: name&lt;br/&gt;
   at MongoDB.Bson.IO.BsonWriter.WriteName(String&#160;name) in BsonWriter.cs: line 506&lt;br/&gt;
   at MongoDB.Bson.Serialization.Serializers.DictionarySerializer`2.Serialize(BsonWriter&#160;bsonWriter,&#160;Type&#160;nominalType,&#160;Object&#160;value,&#160;IBsonSerializationOptions&#160;options) in DictionaryGenericSerializer.cs: line 194&lt;br/&gt;
   at MongoDB.Bson.Serialization.BsonClassMapSerializer.SerializeMember(BsonWriter&#160;bsonWriter,&#160;Object&#160;obj,&#160;BsonMemberMap&#160;memberMap) in BsonClassMapSerializer.cs: line 692&lt;br/&gt;
   at MongoDB.Bson.Serialization.BsonClassMapSerializer.Serialize(BsonWriter&#160;bsonWriter,&#160;Type&#160;nominalType,&#160;Object&#160;value,&#160;IBsonSerializationOptions&#160;options) in BsonClassMapSerializer.cs: line 432&lt;br/&gt;
   at MongoDB.Bson.Serialization.BsonSerializer.Serialize(BsonWriter&#160;bsonWriter,&#160;Type&#160;nominalType,&#160;Object&#160;value,&#160;IBsonSerializationOptions&#160;options) in BsonSerializer.cs: line 805&lt;br/&gt;
   at MongoDB.Bson.BsonExtensionMethods.ToJson(Object&#160;obj,&#160;Type&#160;nominalType,&#160;IBsonSerializationOptions&#160;options,&#160;JsonWriterSettings&#160;settings) in BsonExtensionMethods.cs: line 304&lt;br/&gt;
   at MongoDB.Bson.BsonExtensionMethods.ToJson(Object&#160;obj,&#160;Type&#160;nominalType,&#160;JsonWriterSettings&#160;settings) in BsonExtensionMethods.cs: line 319&lt;br/&gt;
   at MongoDB.Bson.BsonExtensionMethods.ToJson(Object&#160;obj,&#160;Type&#160;nominalType) in BsonExtensionMethods.cs: line 271&lt;br/&gt;
   at MongoDB.Bson.BsonExtensionMethods.ToJson(TNominalType&#160;obj) in BsonExtensionMethods.cs: line 220&lt;/p&gt;</description>
                <environment>Windows</environment>
        <key id="120184">CSHARP-930</key>
            <summary>If any of the keys in a Dictionary contains a null character serialization fails</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="4" iconUrl="https://jira.mongodb.org/images/icons/priorities/minor.svg">Minor - P4</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="robert@mongodb.com">Robert Stam</assignee>
                                    <reporter username="bniemyjski">Blake Niemyjski</reporter>
                        <labels>
                    </labels>
                <created>Thu, 13 Mar 2014 15:14:55 +0000</created>
                <updated>Wed, 13 Apr 2016 21:04:32 +0000</updated>
                            <resolved>Fri, 21 Mar 2014 15:03:29 +0000</resolved>
                                    <version>1.9</version>
                                    <fixVersion>1.9</fixVersion>
                                    <component>Serialization</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="520737" author="xgen-internal-githook" created="Fri, 21 Mar 2014 15:03:09 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;rstam&apos;, u&apos;name&apos;: u&apos;rstam&apos;, u&apos;email&apos;: u&apos;robert@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-930&quot; title=&quot;If any of the keys in a Dictionary contains a null character serialization fails&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-930&quot;&gt;&lt;del&gt;CSHARP-930&lt;/del&gt;&lt;/a&gt;: Handle dictionary keys with null characters.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/779ee62f294608dc7101c936b70e98055800b8a5&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/779ee62f294608dc7101c936b70e98055800b8a5&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="515333" author="bniemyjski" created="Thu, 13 Mar 2014 16:51:52 +0000"  >&lt;p&gt;Thanks guys for the explanation. I&apos;ll add some checks to our code before inserting to try and detect null strings. If we could get a check added into the driver to change the representation automatically that would be sweet for others who are not expecting this behavior.&lt;/p&gt;</comment>
                            <comment id="515322" author="rstam" created="Thu, 13 Mar 2014 16:39:51 +0000"  >&lt;p&gt;In your case, the element names are coming from the representation chosen for the dictionary (property G of your class C). You can configure your POCO to use a different representation for dictionaries that will be safe even when some of the dictionary keys have nulls in them (and therefore aren&apos;t safe as element names);&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;public class C&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;{&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    [BsonDictionaryOptions(Representation = DictionaryRepresentation.ArrayOfDocuments)]&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    public Dictionary&amp;lt;string, int&amp;gt; G;&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;The resulting JSON will look slightly different though... so this is a schema change for your application:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;{ &quot;G&quot; : [{ &quot;k&quot; : &quot;\u0000\&quot;&amp;gt;&amp;lt;script&amp;gt;alert(309)&amp;lt;/script&amp;gt;&quot;, &quot;v&quot; : 1 }] }&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;There arguably is a bug here though... and here&apos;s why: the default representation for a Dictionary&amp;lt;K,V&amp;gt; is Dynamic, which means that the serializer looks at the keys and determines whether the keys are safe to use as element names. If they are safe, then it uses the Document representation, otherwise it uses the ArrayOfArrays representation. The bug is that it isn&apos;t looking for nulls.&lt;/p&gt;

&lt;p&gt;If your dictionary has keys that are not valid BSON element names, I would recommend you go ahead and force the desired safe representation (ArrayOfArrays or ArrayOfDocuments). With Dynamic some of your dictionaries might be stored as nested documents, while others might be stored as arrays of key value pairs, depending on what the key values are. By explicitly choosing the representation yourself you get a consistent representation. It&apos;s also a bit faster at runtime since it no longer has to scan the key values to decide what representation to use.&lt;/p&gt;</comment>
                            <comment id="515309" author="rstam" created="Thu, 13 Mar 2014 16:22:02 +0000"  >&lt;p&gt;Nulls are only prohibited by the BSON spec in element names. They are fully supported in string values.&lt;/p&gt;

&lt;p&gt;If you suspect your string data might have the occasional null character then make sure you don&apos;t use those strings as element names, but instead design your schema so that they are values instead of element names.&lt;/p&gt;</comment>
                            <comment id="515295" author="craiggwilson" created="Thu, 13 Mar 2014 16:15:47 +0000"  >&lt;p&gt;Thanks for the test...  MongoDB does not allow nulls inside element names as documented in the &lt;a href=&quot;http://bsonspec.org/#/specification&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;bsonspec&lt;/a&gt;.  See the e_name and the corresponding documentation on a CSTRING.&lt;/p&gt;

&lt;p&gt;Since C# is a unicode language, C# is taking your string and converting \u0000 to null. In turn, the .NET driver takes a null and attempts to write it as UTF-8 null.  This is what is happening in your test case. It might not be what is happening in your application.  You can make the test pass by using a string literal in your test case (or escaping the first slash in your unicode string).&lt;/p&gt;

&lt;p&gt;Let me know if this makes sense or if you still think there is an issue.&lt;br/&gt;
Craig&lt;/p&gt;</comment>
                            <comment id="515209" author="bniemyjski" created="Thu, 13 Mar 2014 15:16:48 +0000"  >&lt;p&gt;I&apos;ve added a pull request here with a breaking unit test:  &lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/pull/178&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/pull/178&lt;/a&gt;&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                        <customfield id="customfield_10011" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Backwards Compatibility</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10038"><![CDATA[Fully Compatible]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hrwq7j:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>105042</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>