Skip to content

Commit

Permalink
rustdoc-search: allow :: and ::
Browse files Browse the repository at this point in the history
This restriction made sense back when spaces separated function
parameters, but now that they separate path components, there's
no real ambiguity any more.

Additionally, the Rust language allows it.
  • Loading branch information
notriddle committed Nov 29, 2023
1 parent abe34e9 commit c28de27
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 26 deletions.
13 changes: 5 additions & 8 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,18 +512,15 @@ function initSearch(rawSearchIndex) {
bindingName,
};
}
const quadcolon = /::\s*::/.exec(path);
if (path.startsWith("::")) {
throw ["Paths cannot start with ", "::"];
} else if (path.endsWith("::")) {
throw ["Paths cannot end with ", "::"];
} else if (path.includes("::::")) {
throw ["Unexpected ", "::::"];
} else if (path.includes(" ::")) {
throw ["Unexpected ", " ::"];
} else if (path.includes(":: ")) {
throw ["Unexpected ", ":: "];
}
const pathSegments = path.split(/::|\s+/);
} else if (quadcolon !== null) {
throw ["Unexpected ", quadcolon[0]];
}
const pathSegments = path.split(/(?:::\s*)|(?:\s+(?:::\s*)?)/);
// In case we only have something like `<p>`, there is no name.
if (pathSegments.length === 0 || (pathSegments.length === 1 && pathSegments[0] === "")) {
if (generics.length > 0 || prevIs(parserState, ">")) {
Expand Down
27 changes: 9 additions & 18 deletions tests/rustdoc-js-std/parser-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ const PARSED = [
userQuery: "a::::b",
error: "Unexpected `::::`",
},
{
query: "a:: ::b",
elems: [],
foundElems: 0,
original: "a:: ::b",
returned: [],
userQuery: "a:: ::b",
error: "Unexpected `:: ::`",
},
{
query: "a::b::",
elems: [],
Expand Down Expand Up @@ -314,24 +323,6 @@ const PARSED = [
userQuery: 'a<->',
error: 'Unexpected `-` after `<`',
},
{
query: "a:: a",
elems: [],
foundElems: 0,
original: 'a:: a',
returned: [],
userQuery: 'a:: a',
error: 'Unexpected `:: `',
},
{
query: "a ::a",
elems: [],
foundElems: 0,
original: 'a ::a',
returned: [],
userQuery: 'a ::a',
error: 'Unexpected ` ::`',
},
{
query: "a<a>:",
elems: [],
Expand Down
48 changes: 48 additions & 0 deletions tests/rustdoc-js-std/parser-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,54 @@ const PARSED = [
userQuery: "a::b",
error: null,
},
{
query: "a:: a",
elems: [{
name: "a:: a",
fullPath: ["a", "a"],
pathWithoutLast: ["a"],
pathLast: "a",
generics: [],
typeFilter: -1,
}],
foundElems: 1,
original: 'a:: a',
returned: [],
userQuery: 'a:: a',
error: null,
},
{
query: "a ::a",
elems: [{
name: "a ::a",
fullPath: ["a", "a"],
pathWithoutLast: ["a"],
pathLast: "a",
generics: [],
typeFilter: -1,
}],
foundElems: 1,
original: 'a ::a',
returned: [],
userQuery: 'a ::a',
error: null,
},
{
query: "a :: a",
elems: [{
name: "a :: a",
fullPath: ["a", "a"],
pathWithoutLast: ["a"],
pathLast: "a",
generics: [],
typeFilter: -1,
}],
foundElems: 1,
original: 'a :: a',
returned: [],
userQuery: 'a :: a',
error: null,
},
{
query: 'A::B,C',
elems: [
Expand Down

0 comments on commit c28de27

Please sign in to comment.