rime / librime

Rime Input Method Engine, the core library
https://rime.im
BSD 3-Clause "New" or "Revised" License
3.44k stars 562 forks source link

map key containing "/" causes error when used in patch value #190

Closed alswl closed 6 years ago

alswl commented 6 years ago

Error message:

E0306 10:00:51.781275 12610 user_dict_manager.cc:197] error creating directory ''.
E0306 10:00:51.781344 12610 user_dict_manager.cc:197] error creating directory ''.
E0306 10:00:51.781399 12610 user_dict_manager.cc:197] error creating directory ''.
E0306 10:00:51.781436 12610 user_dict_manager.cc:233] failed synchronizing 3/3 user dicts.
E0306 10:00:51.795395 12612 config_data.cc:177] copy on write failed; incompatible node type: [
E0306 10:00:51.795413 12612 config_compiler.cc:127] error merging branch [
E0306 10:00:51.795421 12612 config_compiler.cc:127] error merging branch half_shape
E0306 10:00:51.795428 12612 config_compiler.cc:63] failed to merge tree: default:punctuator
E0306 10:00:51.795435 12612 legacy_preset_config_plugin.cc:56] failed to include section default:punctuator
E0306 10:00:51.795445 12612 config_component.cc:235] error building config: double_pinyin.schema

Related configuration:

patch:
  punctuator/half_shape:
      "/" : "/"
      "[": "「"
      "]": "」"

Version: librime 1:1.2.10-1

System version: Arch latest.

If I use librime-1:1.2.9-8, the configuration works.

Prcuvu commented 6 years ago

Try deleting the redundant line:

      "/" : "/"

When double-quoted, some symbols (including /) have to be escaped. It is recommended to use '/' instead.

alswl commented 6 years ago

Thanks, it works for me。

https://github.com/alswl/Rime/commit/62b21b57a37009192c4d9f11a96aea6bc2967cef#diff-447a9df8e6a613947779b70b12b484aaL55

lotem commented 6 years ago
# luna_pinyin.custom.yaml
patch:
  punctuator/half_shape:
    '/': '/'

以上代碼導致錯誤的結果。half_shape 節點會被替換成字符串值 /。 相似地:

__patch:
  map:
    /a: x
    /b/c: y

會得到

map:
  a: x
  b: { c: y }

我可以推測出這跟支持這種用法有關,是允許嘗試對 key 做路徑解析的副作用:

defaults:
  list:
    - item a
    - item b

replaced:
  __include: defaults
  new_key: value
  # the following replaces the list in defaults
  list:
    - item x
    - item y

merged:
  __include: defaults
  new_key: value
  # the /+ suffix merges the sub-node to the list included from defaults
  list/+:
    - added item c

然而這裏的後綴不同於用作路徑分隔符的 / 。只有 __patch: 這級 map 的 key 需要當節點路徑解讀,其他 map 遞歸合併時,key 裏面的 / 不應該解析爲路徑分隔符,只消匹配 /=/+ 兩種後綴。

和我之前改過的 https://github.com/rime/librime/commit/a1df9c5f5dcfbcdf979cd24925c56a9f806914d2 成因類似。

Prcuvu commented 6 years ago

'/' causes error mentioned above when used in patch. I did not validate before posting my point. It was my fault.

alswl commented 6 years ago

FYI, fixed in https://github.com/rime/librime/releases/tag/rime-1.2.10 .