From bd10f552a71ae32e8fbdbe03ec2a7cad3b60e67d Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 16 Sep 2025 10:08:56 +0100 Subject: [PATCH] Bug 40675: Add unit tests for SIP line ending normalization Content-Type: text/plain; charset=utf-8 This patch adds comprehensive unit tests for the add_field function to verify that all types of line endings (Unix \n, Windows \r\n, Mac \r, and mixed) are properly normalized to spaces to prevent SIP message corruption. Tests cover: - Unix line endings (\n) - Windows line endings (\r\n) - Mac line endings (\r) - Mixed line ending combinations - Normal text without line endings - Empty values Signed-off-by: Marcel de Rooy --- t/SIP/Sip.t | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/t/SIP/Sip.t b/t/SIP/Sip.t index 800de5146f..f39a45d13e 100755 --- a/t/SIP/Sip.t +++ b/t/SIP/Sip.t @@ -18,11 +18,11 @@ use Modern::Perl; use Test::NoWarnings; -use Test::More tests => 11; +use Test::More tests => 12; use Test::Warn; BEGIN { - use_ok( 'C4::SIP::Sip', qw( timestamp ) ); + use_ok( 'C4::SIP::Sip', qw( timestamp add_field ) ); } my $date_time = C4::SIP::Sip::timestamp(); @@ -114,3 +114,31 @@ subtest 'remove_password_from_message' => sub { "11 Checkout - empty AC and AND" ); }; + +subtest 'add_field line ending normalization' => sub { + plan tests => 6; + + # Test Unix line endings (\n) + my $field_unix = C4::SIP::Sip::add_field( "AF", "Line one\nLine two\nLine three" ); + is( $field_unix, "AFLine one Line two Line three|", "Unix line endings (\\n) converted to spaces" ); + + # Test Windows line endings (\r\n) + my $field_windows = C4::SIP::Sip::add_field( "AF", "Line one\r\nLine two\r\nLine three" ); + is( $field_windows, "AFLine one Line two Line three|", "Windows line endings (\\r\\n) converted to spaces" ); + + # Test Mac line endings (\r) + my $field_mac = C4::SIP::Sip::add_field( "AF", "Line one\rLine two\rLine three" ); + is( $field_mac, "AFLine one Line two Line three|", "Mac line endings (\\r) converted to spaces" ); + + # Test mixed line endings + my $field_mixed = C4::SIP::Sip::add_field( "AF", "Line one\r\nLine two\nLine three\rLine four" ); + is( $field_mixed, "AFLine one Line two Line three Line four|", "Mixed line endings converted to spaces" ); + + # Test no line endings (should remain unchanged) + my $field_normal = C4::SIP::Sip::add_field( "AF", "Single line message" ); + is( $field_normal, "AFSingle line message|", "Normal text without line endings unchanged" ); + + # Test empty and undefined values + my $field_empty = C4::SIP::Sip::add_field( "AF", "" ); + is( $field_empty, "AF|", "Empty value handled correctly" ); +}; -- 2.39.5