Fix #120140: RNA: Support single quote in path_resolve #120141

Open
YimingWu wants to merge 3 commits from ChengduLittleA/blender:fix-120140 into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

Support single quote in path_resolve so usages like
bpy.data.path_resolve("objects['Cube']") can work with repr() since
it returns paths with single quoted key.

Support single quote in path_resolve so usages like `bpy.data.path_resolve("objects['Cube']")` can work with `repr()` since it returns paths with single quoted key.
YimingWu added the
Module
Core
label 2024-04-01 12:34:37 +02:00
YimingWu added 1 commit 2024-04-01 12:34:46 +02:00
23688498ca Fix #120140: RNA: Support single quote in `path_resolve`
Support single quote in path_resolve so usages like
`bpy.data.path_resolve("objects['Cube']")` can work with `repr()` since
it returns paths with single quoted key.
YimingWu added this to the Python API project 2024-04-01 12:34:53 +02:00
YimingWu requested review from Sybren A. Stüvel 2024-04-01 12:35:16 +02:00
YimingWu added 1 commit 2024-04-02 10:07:38 +02:00
Sybren A. Stüvel requested changes 2024-04-02 14:05:34 +02:00
Dismissed
@ -1480,0 +1505,4 @@
else {
EXPECT_EQ(BLI_str_escape_find_quote_with(item.text, item.quote_character),
item.text + item.expect_offset);
}

What's the reason to write this like this (with a large percentage of the conditional code duplicated), instead of something like:

const char *expect = item.expect_null ? nullptr : item.text + item.expect_offset;
EXPECT_EQ(BLI_str_escape_find_quote_with(item.text, item.quote_character), expect);

In case of test failure, it would be good to know which exact case failed. Something like this I think would help:

EXPECT_EQ(BLI_str_escape_find_quote_with(item.text, item.quote_character), expect)
  << "text={" << item.text << "}, quote_character=" << item.quote_character
  << ", offset=" << item.expect_offset << ", null=" << item.expect_null;
What's the reason to write this like this (with a large percentage of the conditional code duplicated), instead of something like: ```cpp const char *expect = item.expect_null ? nullptr : item.text + item.expect_offset; EXPECT_EQ(BLI_str_escape_find_quote_with(item.text, item.quote_character), expect); ``` In case of test failure, it would be good to know which exact case failed. Something like this I think would help: ```cpp EXPECT_EQ(BLI_str_escape_find_quote_with(item.text, item.quote_character), expect) << "text={" << item.text << "}, quote_character=" << item.quote_character << ", offset=" << item.expect_offset << ", null=" << item.expect_null; ```
@ -1480,0 +1513,4 @@
TEST_F(StringEscapeFindQuote, Simple)
{
/* NOTE: clang-tidy `modernize-raw-string-literal` is disabled as it causes errors with MSVC.
* TODO: investigate resolving with `/Zc:preprocessor` flag. */

This comment raises lots of questions. How is this disabled? Because I don't see any change in this PR that disables it. And what errors does it cause? Would this be solved by switching the const char * to a StringRef/StringRefNull/std::string?

This comment raises lots of questions. How is this disabled? Because I don't see any change in this PR that disables it. And what errors does it cause? Would this be solved by switching the `const char *` to a `StringRef`/`StringRefNull`/`std::string`?
Author
Member

I have no idea what this part is... I copied something from above 😅... I think it's safe to just remove the comment.

I have no idea what this part is... I copied something from above 😅... I think it's safe to just remove the comment.
@ -143,3 +143,3 @@
/* Copy string, taking into account escaped ']' */
if (quoted) {
if (quote_character) {
BLI_str_unescape(buf, *path, len);

This code relies on BLI_str_unescape() doing the right thing, but from reading the code of that function I get the feeling that it doesn't take single quotes into account. This will only come into play when a name has both a single quote and a double quote in there, as only having a single quote will not need escaping:

>>> C.object  # named Arm'ature
bpy.data.objects["Arm'ature"]

>>> C.object  # named Arm'atu"re
bpy.data.objects['Arm\'atu"re']

I feel that asking you to change that too is out of scope for this PR (as that would, IMO, also need another unit test, in an area that doesn't have any unit tests at all yet). So just take this as a notice you can scoop aside and ignore at your leasure ;-)

This code relies on `BLI_str_unescape()` doing the right thing, but from reading the code of that function I get the feeling that it doesn't take single quotes into account. This will only come into play when a name has both a single quote and a double quote in there, as only having a single quote will not need escaping: ```python >>> C.object # named Arm'ature bpy.data.objects["Arm'ature"] >>> C.object # named Arm'atu"re bpy.data.objects['Arm\'atu"re'] ``` I feel that asking you to change that too is out of scope for this PR (as that would, IMO, also need another unit test, in an area that doesn't have any unit tests at all yet). So just take this as a notice you can scoop aside and ignore at your leasure ;-)
Author
Member

Indeed. This is something I didn't catch, which is expected XD since all the legacy string functions are inter-related. I'll see what I can do with the BLI_str_unescape() part, probably trivial.

Indeed. This is something I didn't catch, which is expected XD since all the legacy string functions are inter-related. I'll see what I can do with the `BLI_str_unescape()` part, probably trivial.

Thanks for the PR! I think it's 99% there, just a few questions.

Thanks for the PR! I think it's 99% there, just a few questions.
YimingWu added 1 commit 2024-04-03 07:38:56 +02:00
Sybren A. Stüvel approved these changes 2024-04-05 11:52:54 +02:00
Sybren A. Stüvel left a comment
Member

LGTM, but since this is so core, I'd love some extra eyes on this. @ideasman42 would you want to review this too?

LGTM, but since this is so core, I'd love some extra eyes on this. @ideasman42 would you want to review this too?
Campbell Barton requested changes 2024-04-05 13:52:11 +02:00
Campbell Barton left a comment
Owner

It's late here, I don't have time for full review but have found problems with this patch, there are places where single quotes isn't implemented it's not clear where they are / aren't supposed to be working. Note that not supporting single quotes was an intentional decision, so this isn't really a bug to fix, more a design decision.

It's late here, I don't have time for full review but have found problems with this patch, there are places where single quotes isn't implemented it's not clear where they are / aren't supposed to be working. Note that *not* supporting single quotes was an intentional decision, so this isn't really a bug to fix, more a design decision.

Replied to #120140 (comment) which notes issues caused by this PR.

Replied to https://projects.blender.org/blender/blender/issues/120140#issuecomment-1162674 which notes issues caused by this PR.
Merge conflict checking is in progress. Try again in few moments.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u fix-120140:ChengduLittleA-fix-120140
git checkout ChengduLittleA-fix-120140
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#120141
No description provided.