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:
		@@ -4,7 +4,6 @@ import javafx.event.EventHandler;
 | 
			
		||||
import javafx.scene.control.*;
 | 
			
		||||
import javafx.scene.input.InputEvent;
 | 
			
		||||
 | 
			
		||||
import envoy.client.util.IssueUtil;
 | 
			
		||||
import envoy.event.IssueProposal;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -58,8 +57,10 @@ public final class BugReportPane extends OnlineOnlySettingsPane {
 | 
			
		||||
 | 
			
		||||
		// Displaying the submitReportButton
 | 
			
		||||
		submitReportButton.setDisable(true);
 | 
			
		||||
		submitReportButton.setOnAction(e -> client.send(new IssueProposal(titleTextField.getText(), IssueUtil
 | 
			
		||||
			.sanitizeIssueDescription(errorDetailArea.getText(), showUsernameInBugReport.isSelected() ? client.getSender().getName() : null), true)));
 | 
			
		||||
		submitReportButton.setOnAction(e -> {
 | 
			
		||||
			String title = titleTextField.getText(), description = errorDetailArea.getText();
 | 
			
		||||
			client.send(showUsernameInBugReport.isSelected() ? new IssueProposal(title, description, true) : new IssueProposal(title, description, client.getSender().getName(), true));
 | 
			
		||||
		});
 | 
			
		||||
		getChildren().add(submitReportButton);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,35 +0,0 @@
 | 
			
		||||
package envoy.client.util;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Provides methods to handle outgoing issues.
 | 
			
		||||
 *
 | 
			
		||||
 * @author Leon Hofmeister
 | 
			
		||||
 * @author Kai S. K. Engelbart
 | 
			
		||||
 * @since Envoy Client v0.2-beta
 | 
			
		||||
 */
 | 
			
		||||
public final class IssueUtil {
 | 
			
		||||
 | 
			
		||||
	private IssueUtil() {}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Normalizes line breaks and appends the user name to the issue description if
 | 
			
		||||
	 * requested.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param description the description to sanitize
 | 
			
		||||
	 * @param username    the user who submitted the issue. Should be
 | 
			
		||||
	 *                    {@code null} if he does not want to be named.
 | 
			
		||||
	 * @return the sanitized description
 | 
			
		||||
	 * @since Envoy Client v0.2-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public static String sanitizeIssueDescription(String description, String username) {
 | 
			
		||||
 | 
			
		||||
		// Trim and replace line breaks by <br> tags
 | 
			
		||||
		description = description.trim().replaceAll(System.getProperty("line.separator"), "<br>");
 | 
			
		||||
 | 
			
		||||
		// Append user name if requested
 | 
			
		||||
		if (username != null)
 | 
			
		||||
			description += String.format("<br>Submitted by user %s.", username);
 | 
			
		||||
 | 
			
		||||
		return description;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user