Skip to content
Open
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
44 changes: 44 additions & 0 deletions .github/workflows/ubuntu-debug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Ubuntu 22.04 Debug

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths-ignore:
- '**.md'
- 'docs/**'
push:
branches:
- main
paths-ignore:
- '**.md'
- 'docs/**'

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
ubuntu-build-debug:
strategy:
fail-fast: false
matrix:
shared: [OFF]
cxx: [g++-12, clang++-15]
runs-on: [ubuntu-22.04]
simdutf: [OFF, ON]
runs-on: ${{matrix.runs-on}}
steps:
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
- name: Setup Ninja
run: sudo apt-get install ninja-build
- name: Prepare
run: cmake -DCMAKE_BUILD_TYPE=Debug -D ADA_TESTING=ON -D ADA_BENCHMARKS=ON -DBUILD_SHARED_LIBS=${{matrix.shared}} -D ADA_USE_SIMDUTF=${{matrix.simdutf}} -G Ninja -B build
env:
CXX: ${{matrix.cxx}}
- name: Build
run: cmake --build build -j=4
- name: Test
run: ctest --output-on-failure --test-dir build --timeout 300
19 changes: 17 additions & 2 deletions src/url_aggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,16 +647,26 @@ bool url_aggregator::set_host_or_hostname(const std::string_view input) {
return true;
}

bool url_aggregator::set_host(const std::string_view input) {
bool url_aggregator::set_host(std::string_view input) {
ada_log("url_aggregator::set_host '", input, "'");
ADA_ASSERT_TRUE(validate());
std::string tmp_buffer;
if (helpers::overlaps(input, buffer)) {
tmp_buffer = input;
input = tmp_buffer;
}
ADA_ASSERT_TRUE(!helpers::overlaps(input, buffer));
return set_host_or_hostname<false>(input);
}

bool url_aggregator::set_hostname(const std::string_view input) {
bool url_aggregator::set_hostname(std::string_view input) {
ada_log("url_aggregator::set_hostname '", input, "'");
ADA_ASSERT_TRUE(validate());
std::string tmp_buffer;
if (helpers::overlaps(input, buffer)) {
tmp_buffer = input;
input = tmp_buffer;
}
ADA_ASSERT_TRUE(!helpers::overlaps(input, buffer));
return set_host_or_hostname<true>(input);
}
Expand Down Expand Up @@ -1227,6 +1237,11 @@ bool url_aggregator::parse_ipv6(std::string_view input) {
bool url_aggregator::parse_opaque_host(std::string_view input) {
ada_log("parse_opaque_host ", input, " [", input.size(), " bytes]");
ADA_ASSERT_TRUE(validate());
std::string tmp_buffer;
if (helpers::overlaps(input, buffer)) {
tmp_buffer = input;
input = tmp_buffer;
}
ADA_ASSERT_TRUE(!helpers::overlaps(input, buffer));
if (std::ranges::any_of(input, ada::unicode::is_forbidden_host_code_point)) {
return is_valid = false;
Expand Down
10 changes: 10 additions & 0 deletions tests/basic_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ TYPED_TEST(basic_tests, pluses) {
SUCCEED();
}

TYPED_TEST(basic_tests, overlap_test) {
auto url = ada::parse<TypeParam>("http://example.com/very_long_path_string");
ASSERT_TRUE(url);
// This triggers assertion failure in debug mode for url_aggregator
// because get_pathname() returns a view into the buffer, and set_hostname()
// modifies it.
url->set_hostname(url->get_pathname());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. That's not allowed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are acquiring a view into the URL, and then, at the same time, trying to modify the URL. You need to make a copy first.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that this isn't the correct solution. We already have debug assertions that validates this behavior if i remember correctly it is ADA_DEVELOPMENT_CHECKs

SUCCEED();
}

TYPED_TEST(basic_tests, set_host_should_return_false_sometimes) {
auto r = ada::parse<TypeParam>("mailto:a@b.com");
ASSERT_FALSE(r->set_host("something"));
Expand Down
15 changes: 15 additions & 0 deletions tests/wpt/ada_extra_urltestdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -285,5 +285,20 @@
"pathname": "b/",
"search": "",
"hash": ""
},
{
"input": "http://user:pass@1.2.3.4",
"base": "about:blank",
"href": "http://user:pass@1.2.3.4/",
"origin": "http://1.2.3.4",
"protocol": "http:",
"username": "user",
"password": "pass",
"host": "1.2.3.4",
"hostname": "1.2.3.4",
"port": "",
"pathname": "/",
"search": "",
"hash": ""
}
]
Loading