elementary / code

Code editor designed for elementary OS
https://elementary.io
GNU General Public License v3.0
480 stars 112 forks source link

Fix the app crashing when two folders and their ancestors have the same names #1460

Closed aguillon closed 3 months ago

aguillon commented 3 months ago

Hi!

I think this fixes https://github.com/elementary/code/issues/1440. As mentioned there, a way to reproduce is to open the folders /usr and $HOME/usr. In this case, the issue is not so much that the two folders and their ancestors have the same names, but that find_unique_path does not handle recursion up to the root.

This is my first contribution to a Vala project, ever. In particular, I don't know how to call a code formatter or how to write unit tests (which would make a lot of sense with the present issue). If you show me how, I will gladly update my PR.

jeremypw commented 3 months ago

@aguillon I use vala-lint to flag up elementaryOS code style issues but no automatic code formatting at the moment. The CI will fail if there are serious code style errors (as it does currently).

You can get the source code of vala-lint from https://github.com/vala-lang/vala-lint.git.

There is code style info on the Developer section of the ElementaryOS website.

The project does not currently implement any unit tests so don't worry about that. You can look at other projects like Files and Terminal for examples of how it is done.

I have quickly tried out your fix and it seems to be working! I'll test it a bit more then it should be good to merge.

aguillon commented 3 months ago

Thank you for vala-lint.

As get_parent () can return null I think you need to perform a null check before referencing that parent.

Thank you, indeed this could happen if we add the root as a project. This should work now.