-
-
Notifications
You must be signed in to change notification settings - Fork 126
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
http: validate request parameters #167
Merged
zeylahellyer
merged 5 commits into
twilight-rs:master
from
zeylahellyer:feature/http-validate-request-parameters
May 26, 2020
Merged
http: validate request parameters #167
zeylahellyer
merged 5 commits into
twilight-rs:master
from
zeylahellyer:feature/http-validate-request-parameters
May 26, 2020
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This patch is a continuation of PR #146 with the comments applied. When creating HTTP requests, validate the request parameters. This includes things like checking that the content length of a message is less than or equal to 2000 characters[1], that a new channel's name is within the range of 2-100 characters[2], and more. The request methods that do validation now return results with an error type that is local to the module. For example, the `http::request::channel::UpdateChannel::name` method can return an error, which is defined at `http::request::channel::update_channel::UpdateChannelError`. Validation functions are located in `http::request::validation`, which includes functions that simply return booleans of whether the input is valid or not. Each of these sources where the validation limits are documented. Some things, such as custom emoji names, don't have a documented length limit[3], so validation isn't done for them. [1]: https://discordapp.com/developers/docs/resources/channel#create-message-params [2]: https://discordapp.com/developers/docs/resources/channel#channel-object-channel-structure [3]: https://discordapp.com/developers/docs/resources/emoji#create-guild-emoji-json-params Closes issue #29. Signed-off-by: Vivian Hellyer <vivian@hellyer.dev>
Signed-off-by: Vivian Hellyer <vivian@hellyer.dev>
Erk-
previously approved these changes
May 26, 2020
Should validation for embeds be added here or should that be in a seperate pr? |
Add embed validation for creating and updating messages. This checks the the author name, description, field names, field values, footer text, and title lengths to ensure they aren't too long. The total number of fields is checked as well as the total combined length of all of the above. This addresses comment <#167 (comment)>. Limits are referenced in the documentation to point to <https://discord.com/developers/docs/resources/channel#embed-limits>. Signed-off-by: Vivian Hellyer <vivian@hellyer.dev>
Signed-off-by: Vivian Hellyer <vivian@hellyer.dev>
Erk-
approved these changes
May 26, 2020
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.
Looks good to me
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
c-http
Affects the http crate
m-breaking change
Breaks the public API.
t-feature
Addition of a new feature
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch is a continuation of PR #146 with the comments applied.
When creating HTTP requests, validate the request parameters. This
includes things like checking that the content length of a message is
less than or equal to 2000 characters1, that a new channel's name is
within the range of 2-100 characters2, and more.
The request methods that do validation now return results with an error
type that is local to the module. For example, the
http::request::channel::UpdateChannel::name
method can return anerror, which is defined at
http::request::channel::update_channel::UpdateChannelError
.Validation functions are located in
http::request::validation
, whichincludes functions that simply return booleans of whether the input is
valid or not. Each of these sources where the validation limits are
documented. Some things, such as custom emoji names, don't have a
documented length limit3, so validation isn't done for them.
Closes issue #29.
Signed-off-by: Vivian Hellyer vivian@hellyer.dev