Sanitized Issue Proposals (#58)
Fixes #53 Co-authored-by: kske <kai@kske.dev> Reviewed-on: https://git.kske.dev/zdm/envoy/pulls/58 Reviewed-by: kske <kai@kske.dev> Reviewed-by: DieGurke <maxi@kske.dev>
This commit is contained in:
@ -23,11 +23,46 @@ public final class IssueProposal extends Event<String> {
|
||||
* @since Envoy Common v0.2-beta
|
||||
*/
|
||||
public IssueProposal(String title, String description, boolean isBug) {
|
||||
super(title);
|
||||
this.description = description;
|
||||
super(escape(title));
|
||||
this.description = sanitizeDescription(description);
|
||||
bug = isBug;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param title the title of the reported bug
|
||||
* @param description the description of this bug
|
||||
* @param user the name of the user creating the issue
|
||||
* @param isBug determines whether this {@code IssueProposal} is
|
||||
* supposed to be a
|
||||
* feature or a bug (true = bug, false = feature)
|
||||
* @since Envoy Common v0.2-beta
|
||||
*/
|
||||
public IssueProposal(String title, String description, String user, boolean isBug) {
|
||||
super(escape(title));
|
||||
this.description = sanitizeDescription(description) + String.format("<br>Submitted by user %s.", user);
|
||||
bug = isBug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes an issue description and normalizes its line breaks.
|
||||
*
|
||||
* @param description the description to normalize
|
||||
* @return the normalized description
|
||||
* @since Envoy Common v0.2-beta
|
||||
*/
|
||||
private static String sanitizeDescription(String description) {
|
||||
return escape(description).replaceAll("\r?\n", "<br>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes quotes and backslashes from a string.
|
||||
*
|
||||
* @param raw the string to escape
|
||||
* @return the escaped string
|
||||
* @since Envoy Client v0.2-beta
|
||||
*/
|
||||
private static String escape(String raw) { return raw.replace("\\", "\\\\").replace("\"", "\\\""); }
|
||||
|
||||
/**
|
||||
* @return the description
|
||||
* @since Envoy Common v0.2-beta
|
||||
|
Reference in New Issue
Block a user