Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apr_brigade_split_line fix for LF handling #53

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion buckets/apr_brigade.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,10 @@ APR_DECLARE(apr_status_t) apr_brigade_split_line(apr_bucket_brigade *bbOut,
pos = memchr(str, APR_ASCII_LF, len);
/* We found a match. */
if (pos != NULL) {
apr_bucket_split(e, pos - str + 1);
/* Split if the LF is not the last character in the bucket. */
if ((pos - str + 1) < len) {
apr_bucket_split(e, pos - str + 1);
}
APR_BUCKET_REMOVE(e);
APR_BRIGADE_INSERT_TAIL(bbOut, e);
return APR_SUCCESS;
Expand Down
30 changes: 28 additions & 2 deletions test/testbuckets.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ static apr_bucket_brigade *make_simple_brigade(apr_bucket_alloc_t *ba,
e = apr_bucket_transient_create(first, strlen(first), ba);
APR_BRIGADE_INSERT_TAIL(bb, e);

e = apr_bucket_transient_create(second, strlen(second), ba);
APR_BRIGADE_INSERT_TAIL(bb, e);
if (second) {
e = apr_bucket_transient_create(second, strlen(second), ba);
APR_BRIGADE_INSERT_TAIL(bb, e);
}

return bb;
}
Expand Down Expand Up @@ -214,6 +216,29 @@ static void test_splitline(abts_case *tc, void *data)
apr_bucket_alloc_destroy(ba);
}

static void test_splitline_exactly(abts_case *tc, void *data)
{
apr_bucket_alloc_t *ba = apr_bucket_alloc_create(p);
apr_bucket_brigade *bin, *bout;

bin = make_simple_brigade(ba, "foo bar.\n", NULL);
bout = apr_brigade_create(p, ba);

APR_ASSERT_SUCCESS(tc, "split line",
apr_brigade_split_line(bout, bin,
APR_BLOCK_READ, 100));

ABTS_INT_EQUAL(tc, 1, count_buckets(bout));
ABTS_INT_EQUAL(tc, 0, count_buckets(bin));

flatten_match(tc, "output brigade", bout, "foo bar.\n");

apr_brigade_destroy(bout);
apr_brigade_destroy(bin);
apr_bucket_alloc_destroy(ba);
}


static void test_splitline_eos(abts_case *tc, void *data)
{
apr_bucket_alloc_t *ba = apr_bucket_alloc_create(p);
Expand Down Expand Up @@ -642,6 +667,7 @@ abts_suite *testbuckets(abts_suite *suite)
abts_run_test(suite, test_split, NULL);
abts_run_test(suite, test_bwrite, NULL);
abts_run_test(suite, test_splitline, NULL);
abts_run_test(suite, test_splitline_exactly, NULL);
abts_run_test(suite, test_splitline_eos, NULL);
abts_run_test(suite, test_splitboundary, NULL);
abts_run_test(suite, test_splits, NULL);
Expand Down
Loading