Repository navigation
cortheon: keep search ads, quotes, hrefs and registry hosts when only the spelling differs - #2750
Conversation
|
Thanks @ppardus. Each spelling case has a small test of its own that fails on main, and the test pages are short hand-written snippets, which is what we want. A few things before this can land:
We'll write the CHANGELOG line at landing.
|
|
Thanks @ppardus, that was quick. Duplicates now compare only the scheme and host without case Three small things, then it's ready:
Please also update the description. It still says Once that's pushed and CI is green, it goes on the landing queue. Main freezes tomorrow morning for 1.2.7, so it lands
|
|
Thanks @ppardus, that covers all three. Any whitespace now bounds
|
Maxrio9
left a comment
There was a problem hiding this comment.
I reproduced an additional href parsing defect at head eaaf6393897bfcb83ddea18672aade2261c10c57, using Zig 0.17.0 and the actual parseDuckDuckGo function.
<a class="result__a" title="see href='https://wrong.example/x'" href="https://right.example/page">Example</a>The result URL is https://wrong.example/x, not the real href. Removing the real href still creates a result pointing to the URL inside title. hrefValue finds a substring within another attribute's quoted value and treats it as an attribute name. This is a remaining parsing case, not a claim that this PR introduced the defect.
A local candidate walks attribute names and complete values, then selects the actual href. Evidence:
- Original head: both new regressions fail; ordinary-link and data-href controls pass (2 pass, 2 fail, exit 1).
- Candidate: both new regressions and all 30 existing search tests pass. The combined run is 37 pass, 0 fail (30 existing, 2 new, 4 external review cases, 1 registration stub), exit 0.
- An independent 22-case matrix passes, covering quote styles, boolean attributes, whitespace, data-href values, missing/empty href and malformed quotes.
zig fmt --checkpasses; changed-file lean checks add zero findings;search.zigstays at 600 lines.git apply --checkpasses against this head.
This is a focused local review experiment. Full server/build suites were not run, and it adds no inference or GPU qualification. The existing quoted-> tag-boundary limitation is outside this candidate.
The author-adoption patch below keeps this change on the existing PR:
diff --git a/zig/src/server/cortheon/search.zig b/zig/src/server/cortheon/search.zig
--- a/zig/src/server/cortheon/search.zig
+++ b/zig/src/server/cortheon/search.zig
@@ -109,31 +109,30 @@
return std.mem.eql(u8, a_rest[a_host..], b_rest[b_host..]);
}
-/// The href in a tag. Whitespace bounds the name, and a quote with no closer drops it.
+/// The href in a tag, skipping complete values of other attributes; an unclosed quote drops the result.
fn hrefValue(tag: []const u8) ?[]const u8 {
- var from: usize = 0;
- while (std.ascii.findIgnoreCasePos(tag, from, "href")) |href_name| { // HREF is the same attribute
- if (href_name > 0 and !std.ascii.isWhitespace(tag[href_name - 1])) { // data-href is not this attribute
- from = href_name + 1;
- continue;
+ var at: usize = 0;
+ while (at < tag.len) {
+ while (at < tag.len and std.ascii.isWhitespace(tag[at])) at += 1;
+ const name_start = at;
+ while (at < tag.len and !std.ascii.isWhitespace(tag[at]) and tag[at] != '=') at += 1;
+ const name = tag[name_start..at];
+ while (at < tag.len and std.ascii.isWhitespace(tag[at])) at += 1;
+ if (at == tag.len or tag[at] != '=') continue;
+ at += 1;
+ while (at < tag.len and std.ascii.isWhitespace(tag[at])) at += 1;
+ var start = at;
+ var end = at;
+ if (at < tag.len and (tag[at] == '"' or tag[at] == '\'')) {
+ const quote = tag[at];
+ start += 1;
+ end = std.mem.indexOfScalarPos(u8, tag, start, quote) orelse return null;
+ at = end + 1;
+ } else {
+ while (at < tag.len and !std.ascii.isWhitespace(tag[at]) and tag[at] != '>') at += 1;
+ end = at;
}
- var after = href_name + 4;
- while (after < tag.len and std.ascii.isWhitespace(tag[after])) after += 1; // href = is the same attribute
- if (after >= tag.len or tag[after] != '=') {
- from = href_name + 1;
- continue;
- }
- var v = tag[after + 1 ..];
- while (v.len > 0 and std.ascii.isWhitespace(v[0])) v = v[1..];
- if (v.len > 0 and (v[0] == '"' or v[0] == '\'')) {
- const q = v[0];
- v = v[1..];
- // the rest of the tag is inside this value, so a later href there is not an attribute
- const end = std.mem.indexOfScalar(u8, v, q) orelse return null;
- return v[0..end];
- }
- const end = std.mem.indexOfAny(u8, v, " \t\r\n>") orelse v.len; // unquoted ends at whitespace or >
- return std.mem.trim(u8, v[0..end], " \t\r\n");
+ if (std.ascii.eqlIgnoreCase(name, "href")) return tag[start..end];
}
return null;
}
@@ -595,3 +594,7 @@
try std.testing.expectEqualStrings("q=zig+0.17+%22std.Io%22", (try duckduckgoUrl(a, "zig 0.17 \"std.Io\""))[std.mem.indexOf(u8, try duckduckgoUrl(a, "zig 0.17 \"std.Io\""), "q=").?..]);
try std.testing.expectEqualStrings("a b/c", try decode(a, "a+b%2Fc"));
}
+
+test {
+ _ = @import("search_href_test.zig");
+}
diff --git a/zig/src/server/cortheon/search_href_test.zig b/zig/src/server/cortheon/search_href_test.zig
new file mode 100644
--- /dev/null
+++ b/zig/src/server/cortheon/search_href_test.zig
@@ -0,0 +1,26 @@
+const std = @import("std");
+const search = @import("search.zig");
+
+test "a search result uses its actual href instead of href text in a quoted attribute" {
+ var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
+ defer arena.deinit();
+ const page =
+ \\<div class="result results_links web-result"><h2>
+ \\<a class="result__a" title="see href='https://wrong.example/x'" href="https://right.example/page">Example</a>
+ \\</h2></div>
+ ;
+ const results = try search.parseDuckDuckGo(arena.allocator(), page, 5);
+ try std.testing.expectEqual(@as(usize, 1), results.len);
+ try std.testing.expectEqualStrings("https://right.example/page", results[0].url);
+}
+
+test "href text in a quoted attribute does not create a search result without an href" {
+ var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
+ defer arena.deinit();
+ const page =
+ \\<div class="result results_links web-result"><h2>
+ \\<a class="result__a" title="see href='https://wrong.example/x'">Example</a>
+ \\</h2></div>
+ ;
+ try std.testing.expectEqual(@as(usize, 0), (try search.parseDuckDuckGo(arena.allocator(), page, 5)).len);
+}…ch registry paths exactly
eaaf639 to
aeeca55
Compare
|
Thank you @ppardus. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
|
Thanks @ppardus! This is in TensorFold 1.2.8, out now: https://github.com/ashhart/TensorFold/releases/tag/v1.2.8
|
What this changes
Cortheon drops or misreads DuckDuckGo results and package registry URLs when only the spelling differs.
A search ad whose wrapper uses
CLASS="result …"is still skipped.A search ad whose wrapper uses
class='result …'is still skipped.An HTML result whose class is
class='result__a'is kept.An HTML snippet whose class is
class='result__snippet'is kept.A Lite result whose class is
class="result-link"is kept.An unquoted
href=…on a result is kept, and it ends at a space, tab, CR or LF.A result whose attribute is written
href = "…"is kept.A result whose
hreffollows a newline inside the tag is kept.An earlier attribute that only contains the text
hrefis skipped.A quoted
hrefthat never closes drops the result.A duplicate whose scheme or host differs only in letters is dropped. The path and query keep their case.
PyPI registry JSON is allowed when the host's letters differ. The path stays exact, so
/PYPI/andJSONare refused.npm registry JSON is allowed when the host's letters differ. The
latestpath stays exact.crates.io registry JSON is allowed when the host's letters differ. The path stays exact.
Issue: n/a. Host-testable spelling bugs, with no open issue.
Stacked on: main.
atc overlap --json: n/a.atcis not installed here.Receipt
n/a. This does not reach inference: no lane, sampler, precision or prompt-processing change. Metal and CUDA were not run.