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

Using the .in() validator with a PartialRange never completes #3048

Open
lewisgodowski opened this issue Jul 31, 2023 · 1 comment
Open

Using the .in() validator with a PartialRange never completes #3048

lewisgodowski opened this issue Jul 31, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@lewisgodowski
Copy link

lewisgodowski commented Jul 31, 2023

Describe the bug

I have a test that validates a JSON object query. One of the object's properties is an integer, and it's corresponding validation is as follows:

  static func validations(_ validations: inout Validations) {
    validations.add(.offset, as: Int.self, is: .in(0...))
  }

When the test runs, because the Sequence passed to .in() is unbounded, the test continues to run forever, racking up more and more memory:
Screenshot showing extreme memory usage of test

To Reproduce

Steps to reproduce the behavior:

  1. See above description.

Expected behavior

The .in() validation should not accept an unbounded or partial range.

Environment

  • Vapor Framework version: 4.77.2
  • Vapor Toolbox version: 18.7.1
  • OS version: 13.4.1
@lewisgodowski lewisgodowski added the bug Something isn't working label Jul 31, 2023
@lewisgodowski
Copy link
Author

I'm aware that .range() should be used in this instance, but I think improved type checking here wouldn't hurt. Admittedly my experience with these particular underlying protocols is limited, but perhaps by limiting the input parameters to Collection instead of Sequence?

    public static func `in`<C>(_ collection: C) -> Validator<T>
        where C: Collection, C.Element == T

Although, then this particular method would essentially a duplicate of the other:

    public static func `in`(_ array: T...) -> Validator<T>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant