element icon indicating copy to clipboard operation
element copied to clipboard

Update getPropByPath to support braces and object keys with special characters

Open dgendill opened this issue 3 years ago • 1 comments

Please make sure these boxes are checked before submitting your PR, thank you!

  • [x] Make sure you follow Element's contributing guide (中文 | English | Español | Français).
  • [x] Make sure you are merging your commits to dev branch.
  • [x] Add some descriptions and refer relative issues for you PR.

This PR is related to #22175, #10293, and #17893. Although it's rare, some of us need to lookup props using brace notation and keys that contain special characters. For example when our data looks like this and we need to validate the mountains['Mountain: Mt. Blanca'] property.

{
  mountains: {
    'Mt. Fiji': 1,
    'Mountain: Mt. Blanca': 2
  }
}

This PR updates getPropByPath so it can parse object key paths using brace notation and parse keys containing special characters. It also adds test cases for the getPropByPath function.

I do have an outstanding question related to this code in form-item.vue.

if (path.indexOf(':') !== -1) {
  path = path.replace(/:/, '.');
}

This code will prevent the use of semicolons in object keys. Do you think there is a way to safely remove this? Is there an alternative? This conversions seem like an undocumented feature that the users shouldn't be relying on, but I don't know the code well enough to be certain.

dgendill avatar Dec 04 '22 20:12 dgendill

Why hasn't there been any progress

k644606347 avatar Dec 15 '23 03:12 k644606347