-
Notifications
You must be signed in to change notification settings - Fork 627
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
Kafka topics should not contain special characters #492
Changes from 4 commits
cacdbd4
e1fe46c
bcdc3ef
33028c1
18151c5
76b8524
5adc88c
aed8069
357bb21
696bb5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -349,12 +349,25 @@ Client.prototype.loadMetadataForTopics = function (topics, cb) { | |
}; | ||
|
||
Client.prototype.createTopics = function (topics, isAsync, cb) { | ||
function isValid (str) { | ||
return !/[~`!#$%\^&*+=\-\[\]\\';,/{}|\\":<>\?]/g.test(str); | ||
} | ||
topics = typeof topics === 'string' ? [topics] : topics; | ||
|
||
if (typeof isAsync === 'function' && typeof cb === 'undefined') { | ||
cb = isAsync; | ||
isAsync = true; | ||
} | ||
var validTopics = true; | ||
Object.keys(topics).map(function (elem) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good one (Y) |
||
if (!isValid(topics[elem])) { | ||
validTopics = false; | ||
} | ||
}); | ||
|
||
if (!validTopics) { | ||
return cb(null, 'Some topics contains special characters, please remove them'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets continue with the error first style and call the callback with a new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool. |
||
} | ||
var self = this; | ||
|
||
// first, load metadata to create topics | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could use
validateConfig
inlib/utils.js
?. And it's might be easier to just check for legal characters than invalid ones. Check out the validation used in Topic.scalaBonus points for:
Consumer
,HighLevelConsumer
, andConsumerGroup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Make sense.