From 5cd1da8e1a6b9dd0f97557432f893e313ea33e84 Mon Sep 17 00:00:00 2001 From: Suresh Sundriyal Date: Sun, 19 Apr 2015 00:00:43 -0700 Subject: [PATCH] [pretty] More restrictive IPv4 regex. The regular expression seems to match arbitrary version strings in pretty-print view. Adding a more restrictive regular expression, that should be able to distinguish between valid IPv4 addresses and arbitrary version strings. --- src/data_scanner.cc | 5 ++++- test/Makefile.am | 6 ++++-- test/test_pretty_print.sh | 10 ++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 test/test_pretty_print.sh diff --git a/src/data_scanner.cc b/src/data_scanner.cc index f6d55984..21e1ed32 100644 --- a/src/data_scanner.cc +++ b/src/data_scanner.cc @@ -103,8 +103,11 @@ static struct { { "rangle", pcrepp("\\A(\\>)"), }, - { "ipv4", pcrepp("\\A(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})"), + { "ipv4", pcrepp("\\A(" + "(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\\.){3}" + "(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(?![\\d]))"), }, + { "uuid", pcrepp( "\\A([0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12})"), }, diff --git a/test/Makefile.am b/test/Makefile.am index cffa1a65..a9e21ccd 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -185,7 +185,8 @@ dist_noinst_SCRIPTS = \ test_sql_str_func.sh \ test_sql_fs_func.sh \ test_view_colors.sh \ - test_vt52_curses.sh + test_vt52_curses.sh \ + test_pretty_print.sh dist_noinst_DATA = \ ansi-colors.0.in \ @@ -281,7 +282,8 @@ TESTS = \ test_vt52_curses.sh \ test_top_status \ test_data_parser.sh \ - test_yajlpp + test_yajlpp \ + test_pretty_print.sh DISTCLEANFILES = \ *.dat \ diff --git a/test/test_pretty_print.sh b/test/test_pretty_print.sh new file mode 100644 index 00000000..065be40b --- /dev/null +++ b/test/test_pretty_print.sh @@ -0,0 +1,10 @@ +#! /bin/bash + +echo '2015-04-18T13:16:30.003 198.51.100.45 98.51.100.1549 198.158.100.4<1054 198.51.100.1546 544.9.8.7 98.542.241.99 19143.2.5.6' | \ + run_test ${lnav_test} -n -c ":switch-to-view pretty" + +check_output "pretty print not able to properly grok ipv4?" <98.51.100.154 (unknown) +9 198.158.100.4 (unknown)<1054 198.51.100.1546 544.9.8.7 98.542.241.99 19143.2.5.6 +EOF