forked from influxdata/influxdb-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
influxdata#684: add tag checking for invalid characters
- Loading branch information
1 parent
125a9ca
commit 1d4016b
Showing
4 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
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 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.influxdb.dto.utils; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* {Purpose of This Type}. | ||
* | ||
* {Other Notes Relating to This Type (Optional)} | ||
* | ||
* @author BrentonPoke | ||
* | ||
*/ | ||
public final class CheckTags { | ||
static final String nameRegex = "([a-zA-Z0-9-_]+)"; | ||
static final String valueRegex = "[[:ascii:]]+"; | ||
static final Pattern namePattern = Pattern.compile(nameRegex, Pattern.MULTILINE); | ||
static final Pattern valuePattern = Pattern.compile(valueRegex, Pattern.MULTILINE); | ||
|
||
/** | ||
* Check a single tag's name according to the corresponding regular expression. | ||
* | ||
* @param name | ||
* the tag name | ||
* @return Boolean indicating that the tag name is legal | ||
* | ||
*/ | ||
|
||
public static Boolean isTagNameLegal(String name){ | ||
final Matcher matcher = namePattern.matcher(name); | ||
return matcher.groupCount() == 1 && matcher.matches(); | ||
} | ||
|
||
/** | ||
* Check a single tag's name according to the corresponding regular expression. | ||
* | ||
* @param value | ||
* the tag value | ||
* @return Boolean indicating that the tag value is legal | ||
* | ||
*/ | ||
public static Boolean isTagValueLegal(String value){ | ||
final Matcher matcher = valuePattern.matcher(value); | ||
return matcher.matches(); | ||
} | ||
|
||
} |