-
Notifications
You must be signed in to change notification settings - Fork 857
Adds a simple tool to generate new escape tables #8783
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
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 file contains hidden or 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 file contains hidden or 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 file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| The `escape_mapper` tool is a simple utility that allows one to view | ||
| the existing table used for URL escaping, found in LogUtils, specifically | ||
| the escapify_url_common function. This function allows one to specify | ||
| an alternate table that contains more characters to escape than the | ||
| RFC-compliant default. | ||
|
|
||
| WARNING: the default encoded characters list is currently hardcoded. | ||
|
|
||
| This tool operates in two basic modes: | ||
| 1) print out the default mappings | ||
| 2) print out the new mapping based on the provided argument | ||
|
|
||
| Only one argument is supported to generate a new mapping table, for example: | ||
| ./escape_mapper '&,+/=' |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /** @file | ||
|
|
||
| A brief file description | ||
|
|
||
| @section license License | ||
|
|
||
| Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. The ASF licenses this file | ||
| to you under the Apache License, Version 2.0 (the | ||
| "License"); you may not use this file except in compliance | ||
| with the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| #include <iomanip> | ||
| #include <iostream> | ||
| #include <string_view> | ||
|
|
||
| void | ||
| add_mapping(unsigned char *table, char c) | ||
| { | ||
| int i = c / 8; | ||
| int x = 7 - c % 8; | ||
| int r = 1 << x; | ||
|
|
||
| table[i] = table[i] | r; | ||
| } | ||
|
|
||
| int | ||
| main(int argc, char *argv[]) | ||
| { | ||
| // only support a single arg that contains all the chars we wish to escapify | ||
| if (argc > 1 && argc != 2) { | ||
| std::cerr << "Provide a single argument with a list of characters to add to the default encoding table." << std::endl; | ||
| return (1); | ||
| } | ||
|
|
||
| // default characters supported by the codes_to_escape table found in LogUtils.cc | ||
| unsigned char to_escape[16] = { | ||
| ' ', '"', '#', '%', '<', '>', '[', ']', '\\', '^', '`', '{', '|', '}', '~', 0x7F, | ||
| }; | ||
|
|
||
| unsigned char escape_codes[32] = {0}; | ||
|
|
||
| // indexes 0-3 are marked as "control" | ||
| for (int i = 0; i < 4; i++) { | ||
| escape_codes[i] = 0xFF; | ||
| } | ||
|
|
||
| // add_mapping performs a logical or on the entries, so the above 0xFF values | ||
| // will persist. | ||
| for (auto char_to_escape : to_escape) { | ||
| add_mapping(&escape_codes[0], char_to_escape); | ||
| } | ||
|
|
||
| // add the chars specified in argv | ||
| if (argc > 1) { | ||
| std::string_view escape_characters{argv[1]}; | ||
| for (auto const char_to_escape : escape_characters) { | ||
| std::cout << "Adding '" << char_to_escape << "' to escape mapping table." << std::endl; | ||
| add_mapping(&escape_codes[0], char_to_escape); | ||
| } | ||
| std::cout << std::endl; | ||
| } | ||
|
|
||
| std::string_view qualification{((argc > 1) ? "New" : "Default")}; | ||
| std::cout << qualification << " Escape Mapping Table:" << std::endl; | ||
|
|
||
| for (unsigned long i = 0; i < sizeof(escape_codes) / sizeof(escape_codes[0]); i++) { | ||
| std::cout << std::dec << std::setfill(' ') << std::setw(4) << i << ": 0x"; | ||
| auto const escape_code = static_cast<int>(escape_codes[i]); | ||
| std::cout << std::hex << std::uppercase << std::setfill('0') << std::setw(2) << escape_code << std::endl; | ||
| } | ||
|
|
||
| return 0; | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.