序列化/反序列化连接字符串应该区分大小写吗?

发布于 2024-11-24 23:39:22 字数 1496 浏览 0 评论 0原文

如何以区分大小写的方式反序列化字符串?看起来序列化是区分大小写的,反序列化不区分大小写有什么意义?

在此处输入图像描述

更新:尝试本地化幕后发生的位置和内容,我已设置 DEBUGGER 来下载符号并进入 FCL .NET 代码。我一直坚持这些代码(DbConnectionOptions.cs 第 873-921 行):

private static NameValuePair ParseInternal(Hashtable parsetable, string connectionString, bool buildChain, Hashtable synonyms, bool firstKey) {
    Debug.Assert(null != connectionString, "null connectionstring"); 
    StringBuilder buffer = new StringBuilder();
    NameValuePair localKeychain = null, keychain = null;

        int nextStartPosition = 0; 
        int endPosition = connectionString.Length; 
        while (nextStartPosition < endPosition) {
            int startPosition = nextStartPosition; 

            string keyname, keyvalue;
            nextStartPosition = GetKeyValuePair(connectionString, startPosition, buffer, firstKey, out keyname, out keyvalue);
            if (ADP.IsEmpty(keyname)) { 
                // if (nextStartPosition != endPosition) { throw; }
                break; 
            } 

            string realkeyname = ((null != synonyms) ? (string)synonyms[keyname] : keyname);
            if (!IsKeyNameValid(realkeyname)) { 
                throw ADP.KeywordNotSupported(keyname); 
            }

修改发生在 while 循环内的某个位置,该循环在每次迭代中查找另一个键/值对。不幸的是,我无法将“添加监视”添加到 keyname 和 realkeyname 变量中。我想同义词哈希表在这里也很重要。

  • 我怎样才能看到这些变量值?
  • 接下来我该怎么做才能最终找到修改的确切位置?

How can I deserialize a string in case-sensitive way? It looks like serialization is case-sensitive, what's the point in deserialization being not case-sensitive??

enter image description here

UPDATE: trying to localize where and what is going on under the hood, I've set up DEBUGGER to download symbols and stepped into the FCL .NET code. I've stuck near these code (DbConnectionOptions.cs lines 873-921):

private static NameValuePair ParseInternal(Hashtable parsetable, string connectionString, bool buildChain, Hashtable synonyms, bool firstKey) {
    Debug.Assert(null != connectionString, "null connectionstring"); 
    StringBuilder buffer = new StringBuilder();
    NameValuePair localKeychain = null, keychain = null;

        int nextStartPosition = 0; 
        int endPosition = connectionString.Length; 
        while (nextStartPosition < endPosition) {
            int startPosition = nextStartPosition; 

            string keyname, keyvalue;
            nextStartPosition = GetKeyValuePair(connectionString, startPosition, buffer, firstKey, out keyname, out keyvalue);
            if (ADP.IsEmpty(keyname)) { 
                // if (nextStartPosition != endPosition) { throw; }
                break; 
            } 

            string realkeyname = ((null != synonyms) ? (string)synonyms[keyname] : keyname);
            if (!IsKeyNameValid(realkeyname)) { 
                throw ADP.KeywordNotSupported(keyname); 
            }

The modification occurs somewhere inside the while loop, which looks for another key/value pair in every iteration. Unfortunately I can't 'add watch' to keyname and realkeyname variables. I suppose synonyms Hashtable is also important here.

  • how can I see these variable values?
  • what should I do next to finally find the exact place of modification?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

十雾 2024-12-01 23:39:22

因为(根据文档)对于连接字符串:

关键字不区分大小写。

但是,这些值区分大小写(显然,对于密码等)

Because (as per the documentation) for connection strings:

Keywords are not case sensitive.

The values, however, are case-sensitive (obviously, for passwords etc)

中二柚 2024-12-01 23:39:22

序列化肯定是区分大小写的,但是您的连接字符串不需要 - 您确定您的 ConnectionString 属性没有做一些奇怪的事情,例如:

public string ConnectionString
{
    get
    {
        return this._ConnectionString;
    }
    set
    {
        this._ConnectionString = value != null ? value.ToLower() : null;
    }
}

请注意,SqlConnectionStringBuilder 似乎会执行某些情况连接字符串的“规范化”,即“怪异”不一定需要出现在您的代码中。

尝试在调试器中执行 info.GetValue("ConnectionString", typeof(string)); 并查看返回的结果。

Serialisation definitely is case sensitive, however your connection string doesn't need to be - are you sure that your ConnectionString property isn't doing something weird, for example:

public string ConnectionString
{
    get
    {
        return this._ConnectionString;
    }
    set
    {
        this._ConnectionString = value != null ? value.ToLower() : null;
    }
}

Note that the SqlConnectionStringBuilder appears to do some case "normalisation" of connection strings, i.e. the "weirdness" doesn't necessarily need to be in your code.

Try executing info.GetValue("ConnectionString", typeof(string)); in a debugger and seeing what you get back.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文