diff options
author | eksperimental <eksperimental@users.noreply.github.com> | 2016-02-18 06:50:30 +0700 |
---|---|---|
committer | eksperimental <eksperimental@users.noreply.github.com> | 2016-02-18 07:01:44 +0700 |
commit | 551de744c751c3072b46fe167fc62a289e743737 (patch) | |
tree | f67adb5c9e8f7c646a6b869803b17ccb6d3f01d8 | |
parent | 0407ddc386d7e066f6a57830988881e0a48a8141 (diff) | |
download | elixir-551de744c751c3072b46fe167fc62a289e743737.tar.gz |
Fix System.read_stripped/1 to properly deal with \r\n\t
also: `System.strip_re/2` replaced with `System.strip/1`
-rw-r--r-- | RELEASE.md | 2 | ||||
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | lib/elixir/lib/system.ex | 16 |
3 files changed, 12 insertions, 8 deletions
diff --git a/RELEASE.md b/RELEASE.md index a0c0a7362..e92b085dc 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -34,6 +34,6 @@ This document simply outlines the release process: ## Places where version is mentioned -* VERSION (make sure there is no newline in this file) +* VERSION * CHANGELOG.md * src/elixir.app.src (not lib/elixir/src/elixir.app.src) @@ -1 +1 @@ -1.3.0-dev
\ No newline at end of file +1.3.0-dev diff --git a/lib/elixir/lib/system.ex b/lib/elixir/lib/system.ex index dd4d80341..0aa2c94f2 100644 --- a/lib/elixir/lib/system.ex +++ b/lib/elixir/lib/system.ex @@ -5,21 +5,25 @@ defmodule System do with the VM or the host system. """ - defp strip_re(iodata, pattern) do - :re.replace(iodata, pattern, "", [return: :binary]) + @base_dir :filename.join(__DIR__, "../../..") + @version_file :filename.join(@base_dir, "VERSION") + + defp strip(iodata) do + :re.replace(iodata, "^[\s\r\n\t]+|[\s\r\n\t]+$", "", [:global, return: :binary]) end defp read_stripped(path) do case :file.read_file(path) do {:ok, binary} -> - strip_re(binary, "^\s+|\s+$") - _ -> "" + strip(binary) + _ -> + "" end end # Read and strip the version from the VERSION file. defmacrop get_version do - case read_stripped(:filename.join(__DIR__, "../../../VERSION")) do + case read_stripped(@version_file) do "" -> raise RuntimeError, message: "could not read the version number from VERSION" data -> data end @@ -34,7 +38,7 @@ defmodule System do {:ok, _} -> if :os.find_executable('git') do data = :os.cmd('git rev-parse --short HEAD') - strip_re(data, "\n") + strip(data) else read_stripped(:filename.join(".git", "HEAD")) end |