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

Hex: Handle additional dynamic version reading approaches #4442

Merged
merged 4 commits into from
Nov 30, 2021

Commits on Nov 29, 2021

  1. Expand regexp to only capture nested functions

    I _think_ `#sanitized_content` is meant to make a common Elixir pattern
    safe for parsing (rather, to prevent code execution while we dependency
    management is being performed). Unfortunately, there are no hints in
    either Git commit history or in the pull requests that were opened
    around Elixir package management.
    
    The pattern that this is handling (at least in the fixtures in this
    repo) is the case where there's a top-level file titled VERSION, which
    is read in in the Mixfile's project metadata. We're handling a couple of
    cases here:
    
    ```elixir
    String.trim(File.read("VERSION"))  # String.trim("0.0.1")
    String.trim(File.read!("VERSION")) # String.trim({:ok, "0.0.1"})
    ```
    
    A lot of Elixir code relies on piping output from one function to
    another, which can cause the above pattern to read as:
    
    ```elixir
    "VERSION" |> File.read() |> String.trim()
    "VERSION"
    |> File.read()
    |> String.trim()
    ```
    
    We're not handling these properly, which has led to errors like:
    ```plaintext
    (ArgumentError) cannot pipe "VERSION" into "0.0.1", can only pipe (snip)
    ```
    
    This commit is meant to capture only the former pattern (nested calls),
    so that we can properly handle the latter in upcoming commits.
    landongrindheim committed Nov 29, 2021
    Configuration menu
    Copy the full SHA
    bb16b41 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    7f0a829 View commit details
    Browse the repository at this point in the history
  3. Handle file reads done with piped functions

    Until this commit, we've only handled the following syntax:
    ```elixir
    String.trim(File.read("VERSION"))
    String.trim(File.read!("VERSION"))
    ```
    
    However, we've encountered users using the following idioms:
    ```elixir
    "VERSION" |> File.read() |> String.trim()
    "VERSION" |> File.read!() |> String.trim()
    ```
    and:
    ```elixir
    "VERSION"
    |> File.read()
    |> String.trim()
    
    "VERSION"
    |> File.read!()
    |> String.trim()
    ```
    
    This commit allows us to handle the latter cases, where the pipe
    operator is used.
    landongrindheim committed Nov 29, 2021
    Configuration menu
    Copy the full SHA
    fb042c5 View commit details
    Browse the repository at this point in the history

Commits on Nov 30, 2021

  1. Configuration menu
    Copy the full SHA
    cea0472 View commit details
    Browse the repository at this point in the history