Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Adding new util function for topics validations #495

Merged
merged 3 commits into from
Oct 25, 2016

Conversation

shaikh-shahid
Copy link
Contributor

Leaving the validateTopics topics function as it is because I believe it is meant for validating the topics coming from the send() function. Not sure, though.

validateCreateTopics contains following checks which are similar to what is been done for Kafka here [https://github.com/apache/kafka/blob/trunk/core/src/main/scala/kafka/common/Topic.scala]

  • check if the topic is empty.
  • check if the topic is . or ..
  • check if the topic length is greater than 249 characters.
  • check if the topic, is not ASCII alphanumeric.

Leaving the `validateTopics` topics function as it is because I believe it is meant for validating the topics coming from the `send()` function. Not sure, though.

`validateCreateTopics` contains following checks which are similar to what is been done for Kafka here [https://github.com/apache/kafka/blob/trunk/core/src/main/scala/kafka/common/Topic.scala]

- check if the topic is empty.
- check if the topic is . or ..
- check if the topic length is greater than 249 characters.
- check if the topic, is not ASCII alphanumeric.
For build fix.
Copy link
Collaborator

@hyperlink hyperlink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me other than the items mentioned. Thanks again for your contribution!

throw new InvalidConfigError('topic name cannot be . or ..');
}
if (topic.length > allowedTopicLength) {
throw new InvalidConfigError('topic name is illegal, cannot be longer than ' + allowedTopicLength + ' characters');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind changing to a template literal? We support node 4 now.


function validateConfig (property, value) {
if (!legalChars.test(value)) {
throw new InvalidConfigError([property, value, "is illegal, contains a character other than ASCII alphanumerics, '.', '_' and '-'"].join(' '));
}
}

function validateCreateTopics (topics) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename this to validateTopicNames since this isn't specific to just creating topics but we can reuse this to validate topics in the other classes.

@@ -1,13 +1,34 @@
var assert = require('assert');
var InvalidConfigError = require('./errors/InvalidConfigError');
var legalChars = new RegExp('^[a-zA-Z0-9._-]*$');
var allowedTopicLength = 249;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const ?

throw new InvalidConfigError('topic name is illegal, cannot be longer than ' + allowedTopicLength + ' characters');
}
if (!legalChars.test(topic)) {
throw new InvalidConfigError('topic name ' + topic + 'is illegal, contains a character other than ASCII alphanumerics .,_ and -');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

template literal here as well.

Fixes as per suggestion.
@shaikh-shahid
Copy link
Contributor Author

Done with the changes.

@hyperlink hyperlink merged commit 7232e28 into SOHU-Co:master Oct 25, 2016
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants