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

Flag use of Unicode less-than and greater-than characters in FilePath to be a Windows-only change #215

Conversation

JoshRosen
Copy link
Contributor

@JoshRosen JoshRosen commented Nov 22, 2024

This PR fixes a regression introduced by #208

That PR aimed to fix #200, an issue where std.extVar failed on Windows because it tried to resolve mock paths which contained < and > characters which are forbidden in Windows filenames.

That PR's solution was to use Unicode less-than and greater-than characters in place of ASCII < and >, but that broke things for Unix/Linux platforms with a non-UTF8 LANG (see #208 (review)).

In this PR, I aim to fix this by flagging the other PR's change to only occur for Windows, while continuing to use ASCII < and > as before on other platforms.

I also added a regression test by pinning LANG=C in our GitHub Actions test setup. This successfully reproduced the bug fixed in this PR, and also uncovered a minor test-only issue related to the use of default character encodings (which I've fixed by pinning the test code to UTF-8).

Note that these file paths aren't actually materialized onto disk: rather, these are "placeholder / mock" paths used to indicate when jsonnet is reading from synthetic paths. In theory, we might be able to avoid the need to ever perform resolution in the first place by changing uses of these paths to be an Either of either an actual os.Path or a placeholder, but that's a much larger and more invasive change than I want to make right now. Here, I've chosen to pursue a narrowly-targeted tactical fix-forward.

@@ -33,4 +33,20 @@ object Util{
new String(range.dropWhile(_ < 0).takeWhile(_ < s.length).map(s).toArray)
}
}

val isWindows: Boolean = System.getProperty("os.name").toLowerCase.startsWith("windows")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This matches

public static boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("windows");
, but we can't directly that other implementation here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Come to think of it, though, I'm wondering whether this should be lifted to Platform to ensure it won't blow up on Scala JS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, we need to wrap in options to avoid an NPE under ScalaJS: d745f75

See https://scastie.scala-lang.org/VuigbI2gS5G1WOnTYCdTdg for seeing some default properties in ScalaJS (look at Javascript console output after running).

Copy link
Collaborator

@stephenamar-db stephenamar-db left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this bug!

@stephenamar-db stephenamar-db merged commit 0fff9f9 into databricks:master Nov 26, 2024
1 check 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.

std.extVar are resolved as FilePath in windows
2 participants