Skip to content

Commit

Permalink
Added tests for hyperlink escaping.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcnamara committed May 4, 2015
1 parent 024aea6 commit 9e56b10
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/worksheet.c
Original file line number Diff line number Diff line change
Expand Up @@ -2242,6 +2242,7 @@ worksheet_write_url_opt(lxw_worksheet *self,
for (i = 0; i <= strlen(url_copy); i++) {
switch (url_copy[i]) {
case (' '):
case ('"'):
case ('%'):
case ('<'):
case ('>'):
Expand All @@ -2251,7 +2252,7 @@ worksheet_write_url_opt(lxw_worksheet *self,
case ('^'):
case ('{'):
case ('}'):
sprintf(url_external + strlen(url_external), "%%%2X",
sprintf(url_external + strlen(url_external), "%%%2x",
url_copy[i]);
break;
default:
Expand Down
20 changes: 20 additions & 0 deletions test/functional/src/test_escapes04.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2015, John McNamara, [email protected]
*
*/

#include "xlsxwriter.h"

int main() {

lxw_workbook *workbook = new_workbook("test_escapes04.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);

worksheet_write_url(worksheet, CELL("A1"), "http://www.perl.com/?a=1&b=2" , NULL);

return workbook_close(workbook);
}
23 changes: 23 additions & 0 deletions test/functional/src/test_escapes05.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2015, John McNamara, [email protected]
*
*/

#include "xlsxwriter.h"

int main() {

lxw_workbook *workbook = new_workbook("test_escapes05.xlsx");
lxw_worksheet *worksheet1 = workbook_add_worksheet(workbook, "Start");
lxw_worksheet *worksheet2 = workbook_add_worksheet(workbook, "A & B");

(void)worksheet2;

worksheet_write_url_opt(worksheet1, CELL("A1"), "internal:'A & B'!A1", NULL, "Jump to A & B" , NULL);

return workbook_close(workbook);
}
25 changes: 25 additions & 0 deletions test/functional/src/test_escapes06.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2015, John McNamara, [email protected]
*
*/

#include "xlsxwriter.h"

int main() {

lxw_workbook *workbook = new_workbook("test_escapes06.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_format *num_format = workbook_add_format(workbook);

format_set_num_format(num_format, "[Red]0.0%\\ \"a\"");

worksheet_set_column(worksheet, 0, 0, 14, NULL, NULL);

worksheet_write_number(worksheet, CELL("A1"), 123, num_format);

return workbook_close(workbook);
}
20 changes: 20 additions & 0 deletions test/functional/src/test_escapes07.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2015, John McNamara, [email protected]
*
*/

#include "xlsxwriter.h"

int main() {

lxw_workbook *workbook = new_workbook("test_escapes07.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);

worksheet_write_url(worksheet, CELL("A1"), "http://example.com/!\"$%&'( )*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", NULL);

return workbook_close(workbook);
}
21 changes: 21 additions & 0 deletions test/functional/src/test_escapes08.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2015, John McNamara, [email protected]
*
*/

#include "xlsxwriter.h"

int main() {

lxw_workbook *workbook = new_workbook("test_escapes08.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);

/* Test an already escaped string. */
worksheet_write_url_opt(worksheet, CELL("A1"), "http://example.com/%5b0%5d", NULL, "http://example.com/[0]", NULL);

return workbook_close(workbook);
}
38 changes: 38 additions & 0 deletions test/functional/test_escapes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
###############################################################################
#
# Tests for libxlsxwriter.
#
# Copyright 2014-2015, John McNamara, [email protected]
#

import base_test_class

class TestCompareXLSXFiles(base_test_class.XLSXBaseTest):
"""
Test file created with libxlsxwriter against a file created by Excel.
"""

# def test_escapes01(self):
# self.run_exe_test('test_escapes01')

# def test_escapes02(self):
# self.run_exe_test('test_escapes02')

# def test_escapes03(self):
# self.run_exe_test('test_escapes03')

def test_escapes04(self):
self.run_exe_test('test_escapes04')

def test_escapes05(self):
self.run_exe_test('test_escapes05')

def test_escapes06(self):
self.run_exe_test('test_escapes06')

def test_escapes07(self):
self.run_exe_test('test_escapes07')

def test_escapes08(self):
self.run_exe_test('test_escapes08')
Binary file added test/functional/xlsx_files/escapes04.xlsx
Binary file not shown.
Binary file added test/functional/xlsx_files/escapes05.xlsx
Binary file not shown.
Binary file added test/functional/xlsx_files/escapes06.xlsx
Binary file not shown.
Binary file added test/functional/xlsx_files/escapes07.xlsx
Binary file not shown.
Binary file added test/functional/xlsx_files/escapes08.xlsx
Binary file not shown.

0 comments on commit 9e56b10

Please sign in to comment.