nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: shapesecurity/salvation
Pull request #75 (2015-09-23 04:00:22)

make salvation aware of block-all-mixed-content directive


Patch:
diff --git a/src/main/java/com/shapesecurity/salvation/Parser.java b/src/main/java/com/shapesecurity/salvation/Parser.java
index 483544b..389f810 100644
--- a/src/main/java/com/shapesecurity/salvation/Parser.java
+++ b/src/main/java/com/shapesecurity/salvation/Parser.java
@@ -202,6 +202,7 @@ public class Parser {
                 return new StyleSrcDirective(this.parseSourceList());
             case Referrer:
             case UpgradeInsecureRequests:
+            case BlockAllMixedContent:
                 throw this.createError(
                     "The " + token.value + " directive is not in the CSP specification yet.");
             case Allow:
diff --git a/src/main/java/com/shapesecurity/salvation/tokens/DirectiveNameToken.java b/src/main/java/com/shapesecurity/salvation/tokens/DirectiveNameToken.java
index c82c681..a99a0eb 100644
--- a/src/main/java/com/shapesecurity/salvation/tokens/DirectiveNameToken.java
+++ b/src/main/java/com/shapesecurity/salvation/tokens/DirectiveNameToken.java
@@ -40,6 +40,7 @@ public class DirectiveNameToken extends Token {
 
         Referrer, // in draft at http://www.w3.org/TR/2014/WD-referrer-policy-20140807/#referrer-policy-delivery as of 2015-08-27
         UpgradeInsecureRequests, // in draft at http://www.w3.org/TR/2015/WD-upgrade-insecure-requests-20150424/#delivery as of 2015-08-27
+        BlockAllMixedContent, // W3C Candidate Recommendation at http://www.w3.org/TR/mixed-content/#strict-opt-in as of 2015-09-22
 
         Allow, // never included in an official CSP specification
         Options; // never included in an official CSP specification
@@ -89,6 +90,8 @@ public class DirectiveNameToken extends Token {
                     return Referrer;
                 case "upgrade-insecure-requests":
                     return UpgradeInsecureRequests;
+                case "block-all-mixed-content":
+                    return BlockAllMixedContent;
             }
             return null;
         }


Test patch:
diff --git a/src/test/java/com/shapesecurity/salvation/ParserTest.java b/src/test/java/com/shapesecurity/salvation/ParserTest.java
index ac69753..13aaca5 100644
--- a/src/test/java/com/shapesecurity/salvation/ParserTest.java
+++ b/src/test/java/com/shapesecurity/salvation/ParserTest.java
@@ -461,6 +461,13 @@ public class ParserTest extends CSPTest {
             assertEquals("The upgrade-insecure-requests directive is not in the CSP specification yet.", e2.getMessage());
         }
 
+        try {
+            parse("block-all-mixed-content");
+            fail();
+        } catch (ParseException e3) {
+            assertEquals("The block-all-mixed-content directive is not in the CSP specification yet.", e3.getMessage());
+        }
+
     }
 
     @Test
Repository: shapesecurity/salvation
Pull request #117 (2016-02-18 14:49:02)

Add missing word in report-to error message
Add the word `directive` that was inadvertently omitted from the error message.


Patch:
diff --git a/src/main/java/com/shapesecurity/salvation/Parser.java b/src/main/java/com/shapesecurity/salvation/Parser.java
index 4a40004..76c56f0 100644
--- a/src/main/java/com/shapesecurity/salvation/Parser.java
+++ b/src/main/java/com/shapesecurity/salvation/Parser.java
@@ -547,7 +547,7 @@ public class Parser {
             }
             this.error(token, "Expecting RFC 7230 token but found \"" + token.value + "\".");
         } else {
-            this.error(directiveNameToken, "The report-to must contain exactly one RFC 7230 token.");
+            this.error(directiveNameToken, "The report-to directive must contain exactly one RFC 7230 token.");
         }
         throw INVALID_REPORT_TO_TOKEN;
     }


Test patch:
diff --git a/src/test/java/com/shapesecurity/salvation/ParserTest.java b/src/test/java/com/shapesecurity/salvation/ParserTest.java
index 52e8c59..11b05c0 100644
--- a/src/test/java/com/shapesecurity/salvation/ParserTest.java
+++ b/src/test/java/com/shapesecurity/salvation/ParserTest.java
@@ -347,12 +347,12 @@ public class ParserTest extends CSPTest {
 
         parseWithNotices("report-to ", notices);
         assertEquals(1, notices.size());
-        assertEquals("The report-to must contain exactly one RFC 7230 token.", notices.get(0).message);
+        assertEquals("The report-to directive must contain exactly one RFC 7230 token.", notices.get(0).message);
 
         notices.clear();
         parseWithNotices("report-to д", notices);
         assertEquals(2, notices.size());
-        assertEquals("The report-to must contain exactly one RFC 7230 token.", notices.get(0).message);
+        assertEquals("The report-to directive must contain exactly one RFC 7230 token.", notices.get(0).message);
         assertEquals("Expecting directive-value but found U+0434 (д). Non-ASCII and non-printable characters must be percent-encoded.", notices.get(1).message);
 
         notices.clear();
Repository: shapesecurity/salvation
Pull request #251 (2022-02-28 19:17:43)

Issue 248: Do not parse directives which are missing a space before the value
Addresses [Issue 248](https://github.com/shapesecurity/salvation/issues/248), wherein directives that have a value that does not contain a leading whitespace character should not be parsed.

kingthorin: ```bash
ERROR: Committer e.schlenker@f5.com has not signed the CLA

Please submit a PR to the CLA located at [https://github.com/shapesecurity/CL](https://github.com/shapesecurity/CLA)
```
bakkot: We evidently haven't updated the CLA script since the acquisition, lol. I'll get to that Monday.

Patch:
diff --git a/src/main/java/com/shapesecurity/salvation2/Policy.java b/src/main/java/com/shapesecurity/salvation2/Policy.java
index 2521fa1..b6cf720 100644
--- a/src/main/java/com/shapesecurity/salvation2/Policy.java
+++ b/src/main/java/com/shapesecurity/salvation2/Policy.java
@@ -129,6 +129,10 @@ public class Policy {
 
 			String remainingToken = strippedLeadingAndTrailingWhitespace.substring(directiveName.length());
 
+			if (remainingToken.length() > 0 && !containsLeadingWhitespace(remainingToken)) {
+				throw new IllegalArgumentException("directive value requires leading ascii whitespace");
+			}
+
 			List<String> directiveValues = Utils.splitOnAsciiWhitespace(remainingToken);
 
 			policy.add(directiveName, directiveValues, directiveErrorConsumer);
@@ -1078,6 +1082,11 @@ public class Policy {
 		return string.replaceAll("[" + Constants.WHITESPACE_CHARS + "]+$", "");
 	}
 
+	private static boolean containsLeadingWhitespace(String string) {
+		Matcher matcher = Pattern.compile("[" + Constants.WHITESPACE_CHARS + "]+").matcher(string);
+		return matcher.find() && matcher.start() == 0;
+	}
+
 	@Nonnull
 	private static String collect(String input, String regex) {
 		Matcher matcher = Pattern.compile(regex).matcher(input);


Test patch:
diff --git a/src/test/java/com/shapesecurity/salvation2/ParserTest.java b/src/test/java/com/shapesecurity/salvation2/ParserTest.java
index 10c5995..6fcd5db 100644
--- a/src/test/java/com/shapesecurity/salvation2/ParserTest.java
+++ b/src/test/java/com/shapesecurity/salvation2/ParserTest.java
@@ -407,6 +407,13 @@ public class ParserTest extends TestBase {
 		);
 	}
 
+	@Test(expected = IllegalArgumentException.class)
+	public void testIllegalLackOfWhitespace() {
+		roundTrips(
+				"default-src'self'"
+		);
+	}
+
 	@Test
 	public void testNone() {
 		// This asserts that it serializes to the same, uppercased, value
Repository: skiptests/astraea
Pull request #22 (2021-09-15 12:53:45)

Let CloseableThread could execute once.
Add a new method and a new variable in `CloseableThread` to set the thread. Make the thread execute once.


Patch:
diff --git a/app/src/main/java/org/astraea/performance/latency/CloseableThread.java b/app/src/main/java/org/astraea/performance/latency/CloseableThread.java
index baa3afb9..2051f88a 100644
--- a/app/src/main/java/org/astraea/performance/latency/CloseableThread.java
+++ b/app/src/main/java/org/astraea/performance/latency/CloseableThread.java
@@ -7,11 +7,22 @@ import java.util.concurrent.atomic.AtomicBoolean;
 abstract class CloseableThread implements Runnable, Closeable {
   private final AtomicBoolean closed = new AtomicBoolean();
   private final CountDownLatch closeLatch = new CountDownLatch(1);
+  private final boolean executeOnce;
+
+  protected CloseableThread() {
+    this(false);
+  }
+
+  protected CloseableThread(boolean executeOnce) {
+    this.executeOnce = executeOnce;
+  }
 
   @Override
   public final void run() {
     try {
-      while (!closed.get()) execute();
+      do {
+        execute();
+      } while (!closed.get() && !executeOnce);
     } catch (InterruptedException e) {
       // swallow
     } finally {


Test patch:
diff --git a/app/src/test/java/org/astraea/performance/latency/CloseableThreadTest.java b/app/src/test/java/org/astraea/performance/latency/CloseableThreadTest.java
index 27caa355..083003a6 100644
--- a/app/src/test/java/org/astraea/performance/latency/CloseableThreadTest.java
+++ b/app/src/test/java/org/astraea/performance/latency/CloseableThreadTest.java
@@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test;
 class CloseableThreadTest {
 
   @Test
-  void testAllActions() throws InterruptedException {
+  void testExecuteAndCleanup() throws InterruptedException {
     var executeCount = new AtomicInteger();
     var cleanupCount = new AtomicInteger();
     var thread =
@@ -38,4 +38,24 @@ class CloseableThreadTest {
     Assertions.assertTrue(executeCount.get() > 0);
     Assertions.assertEquals(1, cleanupCount.get());
   }
+
+  @Test
+  void testExecuteOnce() throws InterruptedException {
+    var executeCount = new AtomicInteger();
+    var thread =
+        new CloseableThread(true) {
+          @Override
+          void execute() {
+            executeCount.incrementAndGet();
+          }
+        };
+
+    var service = Executors.newSingleThreadExecutor();
+    service.execute(thread);
+    service.shutdown();
+
+    Assertions.assertTrue(service.awaitTermination(10, TimeUnit.SECONDS));
+
+    Assertions.assertEquals(1, executeCount.get());
+  }
 }
Repository: skiptests/astraea
Pull request #85 (2021-11-01 01:28:29)

add Header#of(String, byte[])
不小心把常用的方法刪掉了...


Patch:
diff --git a/app/src/main/java/org/astraea/consumer/Header.java b/app/src/main/java/org/astraea/consumer/Header.java
index b6315506..20d9c38b 100644
--- a/app/src/main/java/org/astraea/consumer/Header.java
+++ b/app/src/main/java/org/astraea/consumer/Header.java
@@ -7,10 +7,15 @@ import org.apache.kafka.common.header.Headers;
 import org.apache.kafka.common.header.internals.RecordHeaders;
 
 public final class Header implements org.apache.kafka.common.header.Header {
+
+  public static Header of(String key, byte[] value) {
+    return new Header(key, value);
+  }
+
   private final String key;
   private final byte[] value;
 
-  public Header(String key, byte[] value) {
+  private Header(String key, byte[] value) {
     this.key = key;
     this.value = value;
   }


Test patch:
diff --git a/app/src/test/java/org/astraea/producer/ProducerTest.java b/app/src/test/java/org/astraea/producer/ProducerTest.java
index b57d6f58..f2add21b 100644
--- a/app/src/test/java/org/astraea/producer/ProducerTest.java
+++ b/app/src/test/java/org/astraea/producer/ProducerTest.java
@@ -19,7 +19,7 @@ public class ProducerTest extends RequireBrokerCluster {
     var topicName = "testSender-" + System.currentTimeMillis();
     var key = "key";
     var timestamp = System.currentTimeMillis() + 10;
-    var header = new Header("a", "b".getBytes());
+    var header = Header.of("a", "b".getBytes());
     try (var producer =
         Producer.builder().brokers(bootstrapServers()).keySerializer(Serializer.STRING).build()) {
       var metadata =