More robust URI detection in tabular exporter. Closes #2213.
This commit is contained in:
parent
4edbd40b6a
commit
78853f8fb2
@ -34,6 +34,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
package com.google.refine.exporters;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.OffsetDateTime;
|
||||
@ -371,9 +373,12 @@ abstract public class CustomizableTabularExporterUtilities {
|
||||
if (value instanceof String) {
|
||||
text = (String) value;
|
||||
|
||||
if(text.contains(":")) {
|
||||
if(urlValidator.isValid(text)) {
|
||||
link = text;
|
||||
if(text.contains(":") && urlValidator.isValid(text)) {
|
||||
// Extra check for https://github.com/OpenRefine/OpenRefine/issues/2213
|
||||
try {
|
||||
link = new URI(text).toString();
|
||||
} catch(URISyntaxException e) {
|
||||
;
|
||||
}
|
||||
}
|
||||
} else if (value instanceof OffsetDateTime) {
|
||||
|
@ -43,6 +43,7 @@ import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.Properties;
|
||||
|
||||
@ -156,6 +157,30 @@ public class XlsxExporterTests extends RefineTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exportXlsxStringWithURLs() throws IOException{
|
||||
String url = "GET /primo-library/,http:%2F%2Fcatalogue.unice.fr HTTP/1.1";
|
||||
createDateGrid(2, 2, url);
|
||||
|
||||
try {
|
||||
SUT.export(project, options, engine, stream);
|
||||
} catch (IOException e) {
|
||||
Assert.fail();
|
||||
}
|
||||
|
||||
ByteArrayInputStream inStream = new ByteArrayInputStream( stream.toByteArray() );
|
||||
try {
|
||||
XSSFWorkbook wb = new XSSFWorkbook(inStream);
|
||||
XSSFSheet ws = wb.getSheetAt(0);
|
||||
XSSFRow row1 = ws.getRow(1);
|
||||
XSSFCell cell0 = row1.getCell(0);
|
||||
Assert.assertTrue(cell0.toString().contains("primo-library"));
|
||||
wb.close();
|
||||
} catch (IOException e) {
|
||||
Assert.fail();
|
||||
}
|
||||
}
|
||||
|
||||
//helper methods
|
||||
|
||||
protected void CreateColumns(int noOfColumns){
|
||||
@ -180,13 +205,13 @@ public class XlsxExporterTests extends RefineTest {
|
||||
}
|
||||
}
|
||||
|
||||
private void createDateGrid(int noOfRows, int noOfColumns, OffsetDateTime now){
|
||||
private void createDateGrid(int noOfRows, int noOfColumns, Serializable value){
|
||||
CreateColumns(noOfColumns);
|
||||
|
||||
for(int i = 0; i < noOfRows; i++){
|
||||
Row row = new Row(noOfColumns);
|
||||
for(int j = 0; j < noOfColumns; j++){
|
||||
row.cells.add(new Cell(now, null));
|
||||
row.cells.add(new Cell(value, null));
|
||||
}
|
||||
project.rows.add(row);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user