Skip to content

Commit b53a62d

Browse files
committed
pmd fixes
1 parent dcfb872 commit b53a62d

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

src/main/java/org/htmlunit/csp/Policy.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,16 @@ private Directive add(final String name, final List<String> values,
186186

187187
case "block-all-mixed-content":
188188
// https://www.w3.org/TR/mixed-content/#strict-opt-in
189-
if (!blockAllMixedContent_) {
189+
if (blockAllMixedContent_) {
190+
wasDupe = true;
191+
}
192+
else {
190193
if (!values.isEmpty()) {
191194
directiveErrorConsumer.add(Severity.Error,
192195
"The block-all-mixed-content directive does not support values", 0);
193196
}
194197
blockAllMixedContent_ = true;
195198
}
196-
else {
197-
wasDupe = true;
198-
}
199199
newDirective = new Directive(values);
200200
break;
201201

@@ -322,16 +322,16 @@ else if (values.size() == 1) {
322322

323323
case "upgrade-insecure-requests":
324324
// https://www.w3.org/TR/upgrade-insecure-requests/#delivery
325-
if (!upgradeInsecureRequests_) {
325+
if (upgradeInsecureRequests_) {
326+
wasDupe = true;
327+
}
328+
else {
326329
if (!values.isEmpty()) {
327330
directiveErrorConsumer.add(Severity.Error,
328331
"The upgrade-insecure-requests directive does not support values", 0);
329332
}
330333
upgradeInsecureRequests_ = true;
331334
}
332-
else {
333-
wasDupe = true;
334-
}
335335
newDirective = new Directive(values);
336336
break;
337337

@@ -383,8 +383,7 @@ public String toString() {
383383
first = false;
384384
out.append(directive.name_);
385385
for (final String value : directive.directive_.getValues()) {
386-
out.append(' ');
387-
out.append(value);
386+
out.append(' ').append(value);
388387
}
389388
}
390389
return out.toString();

src/main/java/org/htmlunit/csp/directive/HostSourceDirective.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,19 @@ void addHostOrSchemeDuringConstruction(final String token,
7171
}
7272
else if ("*".equals(lowcaseToken)) {
7373
// Technically this is just a specific kind of host-source, but it's worth handling explicitly
74-
if (!star_) {
75-
star_ = true;
74+
if (star_) {
75+
errors.add(Policy.Severity.Warning, "Duplicate " + kind + " *", index);
7676
}
7777
else {
78-
errors.add(Policy.Severity.Warning, "Duplicate " + kind + " *", index);
78+
star_ = true;
7979
}
8080
}
8181
else if (lowcaseToken.equals(SELF_SRC)) {
82-
if (!self_) {
83-
self_ = true;
82+
if (self_) {
83+
errors.add(Policy.Severity.Warning, "Duplicate " + kind + " 'self'", index);
8484
}
8585
else {
86-
errors.add(Policy.Severity.Warning, "Duplicate " + kind + " 'self'", index);
86+
self_ = true;
8787
}
8888
}
8989
else {

0 commit comments

Comments
 (0)