AlexStocks commented on code in PR #22:
URL: https://github.com/apache/dubbo-net/pull/22#discussion_r4463445641


##########
Clients/DubboClient.cs:
##########
@@ -1190,9 +1190,13 @@ await 
_metadataManager.RefreshCachedServiceAsync(unavailableServiceName)
                 string nowServiceName = serviceName;
                 if(isFullPath)
                 {
-                    if (serviceName.StartsWith(DubboRootPath) && 
serviceName.EndsWith("/providers"))
+                    if (serviceName.StartsWith(DubboRootPath)

Review Comment:
   🟡 **同一个判断,隔壁方法带 `Ordinal`,这里没带**
   
   这两处是同一个逻辑的两份实现,但比较规则不一致:
   
   ```csharp
   // 第 1193 行(本处,ReflushProviderByPathAsync)
   if (serviceName.StartsWith(DubboRootPath)
       && serviceName.EndsWith(ZooKeeperRegistryPaths.ProvidersSuffix))
   
   // 第 1226 行(TryGetServiceNameFromProviderPath)
   || !providerPath.StartsWith(DubboRootPath, StringComparison.Ordinal)
   ```
   
   不带 `StringComparison` 的重载走的是 **`CurrentCulture` 比较**,而这是路径前缀匹配:在 
culture-sensitive 规则下,ICU 认为「可忽略字符」不参与比较,于是 `"/dubbo/…"` 
的匹配结果会依赖运行机器的语言环境。更实际的问题是**这段代码在 Linux 生产环境与本地 Windows 
开发机上可能给出不同结果**,而注册中心返回的路径属于外部输入。
   
   这次改动正好把这两行都改了一遍(`EndsWith` 
换成了常量),却保留了原有的比较差异——对一次「不改变行为」的重构来说无可指摘,但既然手已经在这两行了,改成 
`StringComparison.Ordinal` 是零风险的收益,而且让两个方法真正等价。
   
   **Suggestion:**
   
   ```csharp
   if (serviceName.StartsWith(DubboRootPath, StringComparison.Ordinal)
       && serviceName.EndsWith(ZooKeeperRegistryPaths.ProvidersSuffix, 
StringComparison.Ordinal))
   ```
   
   如果你希望这一条留到后续 PR(保持本次重构逐字节等价、便于 review),也可以——那就请在第 1193 行加一行 `// TODO(#20): 与 
TryGetServiceNameFromProviderPath 对齐为 StringComparison.Ordinal`,否则它会被一直带下去。



##########
Clients/RegistryClient/ZooKeeperRegistryPaths.cs:
##########
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace DubboNet.Clients.RegistryClient
+{
+    /// <summary>
+    /// ZooKeeper 注册节点的默认根路径与目录片段;不用于 Nacos 分组或服务名。
+    /// <para>EN: ZooKeeper registry root and node segments, not Nacos groups 
or service names.</para>
+    /// </summary>
+    internal static class ZooKeeperRegistryPaths
+    {
+        internal const string DefaultRoot = "/dubbo";

Review Comment:
   💭 **`DefaultRoot` 有两种用法,建议在名字或注释上区分开**
   
   `"/dubbo"`(无尾斜杠)和 `"/dubbo/"`(有尾斜杠)在这个类里同时被当作「根」用:
   
   ```csharp
   // 作为裸 root:NormalizeDubboRootPath 的兜底、ResolveRegistryPaths 的元数据根
   string normalized = string.IsNullOrWhiteSpace(rootPath) ? 
ZooKeeperRegistryPaths.DefaultRoot : ...
   
   // 作为前缀(必须有尾斜杠):
   public string DubboRootPath { get; private set; } = 
ZooKeeperRegistryPaths.DefaultRoot + "/";
   ```
   
   也就是说调用方必须知道「`DubboRootPath` 是前缀,要拼服务名;`DefaultRoot` 是裸根,直接比较」。而 
`NormalizeDubboRootPath` 自己又会 `TrimEnd('/') + "/"` 补回来——三条路径各自处理斜杠。
   
   这个类存在的目的就是让「斜杠到底在哪」只有一个答案,现在它反而成了需要记住两条规则的地方。
   
   **Suggestion:** 加一个明确表示前缀形态的常量,把 `+ "/"` 收进来:
   
   ```csharp
   internal const string DefaultRoot = "/dubbo";
   internal const string DefaultRootWithSeparator = DefaultRoot + "/";   // 
拼接服务名时用这个
   ```
   
   `DubboRootPath` 的初始值改用 `DefaultRootWithSeparator`;`NormalizeDubboRootPath` 
的兜底仍用 `DefaultRoot`。这样「哪个是前缀、哪个是裸根」在常量名上就是自解释的,不必依赖调用点上下文。



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to