8000 Ignore not valid extension name in jackson CloudEventDeserializer by mhyeon-lee · Pull Request #429 · cloudevents/sdk-java · GitHub
[go: up one dir, main page]

Skip to content

Ignore not valid extension name in jackson CloudEventDeserializer #429

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

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Ignore not valid extension name in jackson CloudEventDeserializer
Signed-off-by: mhyeon-lee <mhyeon.lee@navercorp.com>
  • Loading branch information
mhyeon-lee committed Dec 7, 2021
commit 20f367da2457b047c6a579d90d7dc7384a78ddd6
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,13 @@ public <T extends CloudEventWriter<V>, V> V read(CloudEventWriterFactory<T, V> w

// Now let's process the extensions
node.fields().forEachRemaining(entry -> {
String extensionName = entry.getKey();
String extensionName = entry.getKey().toLowerCase();

// ignore not valid extension name
if (!this.isValidExtensionName(extensionName)) {
return;
}

JsonNode extensionValue = entry.getValue();

switch (extensionValue.getNodeType()) {
Expand Down Expand Up @@ -192,6 +198,27 @@ private void assertNodeType(JsonNode node, JsonNodeType type, String attributeNa
);
}
}

/**
* Validates the extension name as defined in CloudEvents spec.
*
* @param name the extension name
* @return true if extension name is valid, false otherwise
* @see <a href="https://github.com/cloudevents/spec/blob/master/spec.md#attribute-naming-convention">attribute-naming-convention</a>
*/
private boolean isValidExtensionName(String name) {
for (int i = 0; i < name.length(); i++) {
if (!isValidChar(name.charAt(i))) {
return false;
}
}
return true;
}

private boolean isValidChar(char c) {
return (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9');
}

}

@Override
Expand Down
0