Skip to content

Commit c98c99b

Browse files
authored
Merge pull request #34 from volkanunsal/fix/issue-25-rruleset-parsing-whitespace
Fix RRULESET parsing with indented/whitespace input
2 parents 8d65d82 + a0db14b commit c98c99b

File tree

4 files changed

+77
-7
lines changed

4 files changed

+77
-7
lines changed

postgres-rrule.sql

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
-- postgres-rrule v2.1.0
2-
-- Generated on 2026-02-04 17:21:30 UTC
3-
41
DROP SCHEMA IF EXISTS _rrule CASCADE;
52

63
DROP CAST IF EXISTS (_rrule.RRULE AS TEXT);
@@ -149,7 +146,7 @@ $$ LANGUAGE SQL IMMUTABLE STRICT PARALLEL SAFE;-- Extracts a line value from mul
149146
CREATE OR REPLACE FUNCTION _rrule.extract_line (input TEXT, marker TEXT)
150147
RETURNS TEXT AS $$
151148
-- Clear spaces at the front of the lines
152-
WITH trimmed_input as (SELECT regexp_replace(input, '^\s*', '', 'ng') "r"),
149+
WITH trimmed_input as (SELECT regexp_replace(input, '^[ \t]*', '', 'ng') "r"),
153150
-- Clear all lines except the ones starting with marker
154151
filtered_lines as (SELECT regexp_replace(trimmed_input."r", '^(?!' || marker || ').*?$', '', 'ng') "r" FROM trimmed_input),
155152
-- Replace carriage returns with blank space.
@@ -165,7 +162,7 @@ $$ LANGUAGE SQL IMMUTABLE STRICT PARALLEL SAFE;
165162
CREATE OR REPLACE FUNCTION _rrule.parse_line (input TEXT, marker TEXT)
166163
RETURNS SETOF TEXT AS $$
167164
-- Clear spaces at the front of the lines
168-
WITH trimmed_input as (SELECT regexp_replace(input, '^\s*', '', 'ng') "r"),
165+
WITH trimmed_input as (SELECT regexp_replace(input, '^[ \t]*', '', 'ng') "r"),
169166
-- Clear all lines except the ones starting with marker
170167
filtered_lines as (SELECT regexp_replace(trimmed_input."r", '^(?!' || marker || ').*?$', '', 'ng') "r" FROM trimmed_input),
171168
-- Replace carriage returns with blank space.

src/functions/0004-extract_line.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
CREATE OR REPLACE FUNCTION _rrule.extract_line (input TEXT, marker TEXT)
1010
RETURNS TEXT AS $$
1111
-- Clear spaces at the front of the lines
12-
WITH trimmed_input as (SELECT regexp_replace(input, '^\s*', '', 'ng') "r"),
12+
WITH trimmed_input as (SELECT regexp_replace(input, '^[ \t]*', '', 'ng') "r"),
1313
-- Clear all lines except the ones starting with marker
1414
filtered_lines as (SELECT regexp_replace(trimmed_input."r", '^(?!' || marker || ').*?$', '', 'ng') "r" FROM trimmed_input),
1515
-- Replace carriage returns with blank space.

src/functions/0005-parse_line.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CREATE OR REPLACE FUNCTION _rrule.parse_line (input TEXT, marker TEXT)
22
RETURNS SETOF TEXT AS $$
33
-- Clear spaces at the front of the lines
4-
WITH trimmed_input as (SELECT regexp_replace(input, '^\s*', '', 'ng') "r"),
4+
WITH trimmed_input as (SELECT regexp_replace(input, '^[ \t]*', '', 'ng') "r"),
55
-- Clear all lines except the ones starting with marker
66
filtered_lines as (SELECT regexp_replace(trimmed_input."r", '^(?!' || marker || ').*?$', '', 'ng') "r" FROM trimmed_input),
77
-- Replace carriage returns with blank space.

tests/test_whitespace_parsing.sql

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
BEGIN;
2+
3+
SELECT plan(8);
4+
5+
SET search_path TO _rrule, public;
6+
7+
-- Test 1: RRULESET with space-indented lines (exact scenario from issue #25)
8+
SELECT is(
9+
(rruleset('
10+
DTSTART:19970902T090000
11+
RRULE:FREQ=WEEKLY;UNTIL=19980902T090000
12+
'))."dtstart"::TEXT,
13+
'1997-09-02 09:00:00',
14+
'RRULESET with space-indented lines parses DTSTART correctly'
15+
);
16+
17+
-- Test 2: Verify the RRULE is also parsed correctly from indented input
18+
SELECT is(
19+
((rruleset('
20+
DTSTART:19970902T090000
21+
RRULE:FREQ=WEEKLY;UNTIL=19980902T090000
22+
'))."rrule")[1]."freq"::TEXT,
23+
'WEEKLY',
24+
'RRULESET with space-indented lines parses RRULE FREQ correctly'
25+
);
26+
27+
-- Test 3: RRULESET with tab-indented lines
28+
SELECT is(
29+
(rruleset(E'\tDTSTART:19970902T090000\n\tRRULE:FREQ=DAILY;COUNT=10\n'))."dtstart"::TEXT,
30+
'1997-09-02 09:00:00',
31+
'RRULESET with tab-indented lines parses DTSTART correctly'
32+
);
33+
34+
-- Test 4: Verify RRULE from tab-indented input
35+
SELECT is(
36+
((rruleset(E'\tDTSTART:19970902T090000\n\tRRULE:FREQ=DAILY;COUNT=10\n'))."rrule")[1]."freq"::TEXT,
37+
'DAILY',
38+
'RRULESET with tab-indented lines parses RRULE FREQ correctly'
39+
);
40+
41+
-- Test 5: RRULESET with mixed whitespace (spaces and tabs)
42+
SELECT is(
43+
(rruleset(E' \tDTSTART:19970902T090000\n \t RRULE:FREQ=MONTHLY;COUNT=5\n'))."dtstart"::TEXT,
44+
'1997-09-02 09:00:00',
45+
'RRULESET with mixed spaces and tabs parses DTSTART correctly'
46+
);
47+
48+
-- Test 6: Verify RRULE from mixed whitespace input
49+
SELECT is(
50+
((rruleset(E' \tDTSTART:19970902T090000\n \t RRULE:FREQ=MONTHLY;COUNT=5\n'))."rrule")[1]."freq"::TEXT,
51+
'MONTHLY',
52+
'RRULESET with mixed spaces and tabs parses RRULE FREQ correctly'
53+
);
54+
55+
-- Test 7: Regression test - RRULESET without any indentation still works
56+
SELECT is(
57+
(rruleset('DTSTART:19970902T090000
58+
RRULE:FREQ=WEEKLY;UNTIL=19980902T090000'))."dtstart"::TEXT,
59+
'1997-09-02 09:00:00',
60+
'RRULESET without indentation still parses DTSTART correctly (regression)'
61+
);
62+
63+
-- Test 8: Regression test - RRULE without indentation still works
64+
SELECT is(
65+
((rruleset('DTSTART:19970902T090000
66+
RRULE:FREQ=WEEKLY;UNTIL=19980902T090000'))."rrule")[1]."freq"::TEXT,
67+
'WEEKLY',
68+
'RRULESET without indentation still parses RRULE FREQ correctly (regression)'
69+
);
70+
71+
SELECT * FROM finish();
72+
73+
ROLLBACK;

0 commit comments

Comments
 (0)