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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/pr-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jobs:
runs-on: ubuntu-latest
strategy:
fail-fast: false
env:
# Set LANG=C to simulate least-common-denominator target deployment environments:
LANG: C
stephenamar-db marked this conversation as resolved.
Show resolved Hide resolved

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion sjsonnet/src-jvm-native/sjsonnet/SjsonnetMain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ object SjsonnetMain {
std: Val.Obj = new Std().Std): Either[String, String] = {

val (jsonnetCode, path) =
if (config.exec.value) (file, wd / "\uFE64exec\uFE65")
if (config.exec.value) (file, wd / Util.wrapInLessThanGreaterThan("exec"))
else {
val p = os.Path(file, wd)
(os.read(p), p)
Expand Down
2 changes: 1 addition & 1 deletion sjsonnet/src/sjsonnet/Interpreter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Interpreter(extVars: Map[String, String],


def parseVar(k: String, v: String) = {
resolver.parse(wd / s"\uFE64$k\uFE65", StaticResolvedFile(v))(evaluator).fold(throw _, _._1)
resolver.parse(wd / Util.wrapInLessThanGreaterThan(k), StaticResolvedFile(v))(evaluator).fold(throw _, _._1)
}

lazy val evaluator: Evaluator = createEvaluator(
Expand Down
19 changes: 19 additions & 0 deletions sjsonnet/src/sjsonnet/Util.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,23 @@ object Util{
new String(range.dropWhile(_ < 0).takeWhile(_ < s.length).map(s).toArray)
}
}

val isWindows: Boolean = {
// This is normally non-null on the JVM, but it might be null in ScalaJS hence the Option:
Option(System.getProperty("os.name")).exists(_.toLowerCase.startsWith("windows"))
}

/**
* Wrap the given string in '<' and '>' brackets for pretty printing.
* On Windows, this uses Unicode less-than and greater-than characters, while on
* other platforms it uses ASCII '<' and '>;
* see https://github.com/databricks/sjsonnet/pull/208 for motivation and context.
*/
def wrapInLessThanGreaterThan(s: String): String = {
if (isWindows) {
s"\uFE64$s\uFE65"
} else {
s"<$s>"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package sjsonnet

import utest._
import java.io.{File, FileWriter}

import java.io.{File, FileOutputStream}
import java.nio.file.Files
import scala.util.Random

object BufferedRandomAccessFileTests extends TestSuite {
// Utility function to create a temporary file with known content
def createTempFile(content: String): File = {
val tempFile = Files.createTempFile(null, null).toFile
val writer = new FileWriter(tempFile)
val fos = new FileOutputStream(tempFile)
try {
writer.write(content)
fos.write(content.getBytes("UTF-8"))
} finally {
writer.close()
fos.close()
}
tempFile
}
Expand Down
Loading