From 18caf042edea7b4e5a4b0b2f8943113384f77a62 Mon Sep 17 00:00:00 2001
From: Yong Wen Chua <lawliet89@users.noreply.github.com>
Date: Mon, 18 Mar 2019 09:43:50 +0800
Subject: [PATCH] Separate lifetimes for `AllowedOrigins::some`

---
 src/lib.rs | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/lib.rs b/src/lib.rs
index 343978b..8fbe8ad 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -572,7 +572,7 @@ impl AllowedOrigins {
     /// Allows some origins
     ///
     /// Validation is not performed at this stage, but at a later stage.
-    pub fn some<S1: AsRef<str>, S2: AsRef<str>>(exact: &[S1], regex: &[S2]) -> Self {
+    pub fn some<'a, 'b, S1: AsRef<str>, S2: AsRef<str>>(exact: &'a [S1], regex: &'b [S2]) -> Self {
         AllOrSome::Some(Origins {
             exact: Some(exact.iter().map(|s| s.as_ref().to_string()).collect()),
             regex: Some(regex.iter().map(|s| s.as_ref().to_string()).collect()),
@@ -1974,6 +1974,20 @@ mod tests {
         let _: CorsOptions = serde_json::from_str(json).expect("to not fail");
     }
 
+    #[test]
+    fn allowed_some_origins_allows_different_lifetimes() {
+        let static_exact = ["http://www.example.com"];
+
+        let random_allocation = vec![1, 2, 3];
+        let port: *const Vec<i32> = &random_allocation;
+        let port = port as u16;
+
+        let random_regex = vec![format!("https://(.+):{}", port)];
+
+        // Should compile
+        let _ = AllowedOrigins::some(&static_exact, &random_regex);
+    }
+
     // The following tests check validation
 
     #[test]