Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public static void prepareTodo(Obligation oblig) throws SW360Exception {
assertNotNull(oblig.getTitle());
assertNotNull(oblig.getObligationLevel());

oblig.setText(normalizeObligationText(oblig.getText()));

if (oblig.whitelist == null) {
oblig.setWhitelist(Collections.emptySet());
}
Expand All @@ -64,6 +66,11 @@ public static void prepareTodo(Obligation oblig) throws SW360Exception {
oblig.setType(TYPE_OBLIGATION);
}

private static String normalizeObligationText(String text) {
// Store printable indentation only to avoid persisting tab control characters in DB text fields.
return text.replace('\t', ' ');
}

public static void prepareLicenseType(LicenseType licenseType) throws SW360Exception {
// Check required fields
assertNotNull(licenseType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@
package org.eclipse.sw360.datahandler.thrift;

import org.junit.Test;
import static org.eclipse.sw360.datahandler.common.SW360Constants.TYPE_USER;
import static org.junit.Assert.assertEquals;
import org.eclipse.sw360.datahandler.thrift.licenses.Obligation;
import org.eclipse.sw360.datahandler.thrift.licenses.ObligationLevel;
import org.eclipse.sw360.datahandler.thrift.users.User;

import static org.eclipse.sw360.datahandler.common.SW360Constants.TYPE_OBLIGATION;
import static org.eclipse.sw360.datahandler.common.SW360Constants.TYPE_USER;
import static org.eclipse.sw360.datahandler.thrift.ThriftValidate.prepareTodo;
import static org.eclipse.sw360.datahandler.thrift.ThriftValidate.prepareUser;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

public class ThriftValidateTest {
final String DUMMY_EMAIL_ADDRESS = "dummy.name@dummy.domain.tld";
Expand All @@ -40,4 +45,19 @@ public void testPrepareUser() throws Exception {
assertEquals(TYPE_USER, user.getType());
assertFalse(user.isSetCommentMadeDuringModerationRequest());
}

@Test
public void testPrepareTodoNormalizesTabCharacters() throws Exception {
Obligation obligation = new Obligation();
obligation.setTitle("Test Obligation");
obligation.setText("Line1\n\tIndented\tsegment");
obligation.setObligationLevel(ObligationLevel.LICENSE_OBLIGATION);

prepareTodo(obligation);

assertEquals(TYPE_OBLIGATION, obligation.getType());
assertFalse(obligation.getText().contains("\t"));
assertEquals("Line1\n Indented segment", obligation.getText());
assertTrue(obligation.getWhitelist().isEmpty());
}
}