Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Absolute path for windows #4950

Merged
merged 1 commit into from Mar 7, 2020
Merged

Absolute path for windows #4950

merged 1 commit into from Mar 7, 2020

Conversation

Reckordp
Copy link
Contributor

@Reckordp Reckordp commented Mar 7, 2020

On mirb

File.expand_path("~")

Result in windows

(mirb):1: non-absolute home (ArgumentError)

I have added some code for this. I like it when combined :)

@@ -282,7 +282,12 @@ mrb_file__getwd(mrb_state *mrb, mrb_value klass)
static int
mrb_file_is_absolute_path(const char *path)
{
#ifdef _WIN32
if (strlen(path) < 2) return 0;
return path[0] >= 64 && path[0] <= 90 && path[1] == ':'; // 64 to 90 is ASCII
Copy link
Contributor

@mattn mattn Mar 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not enoguh to check paths with slash or backslash. And "c:" is not absolute paths on Windows.

#define IS_PATHSEP(x) (x == '/' || x == '\')
    return (isalpha(path[0]) && path[1] == ':' && IS_PATHSEP(path[2]));
#undef IS_PATHSEP

Also if you want to handle UNC paths, it should check more strictly.

Copy link
Contributor Author

@Reckordp Reckordp Mar 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will adjust it like the source in ruby. just found out about UNC thanks

@matz matz merged commit 30eaee3 into mruby:master Mar 7, 2020
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants