Do not mistake -%i and -@i for the -i continue flag#618
Open
xroche wants to merge 2 commits into
Open
Conversation
The pass that counts URLs also detects -i (continue), and for anything cmdl_opt() calls an option it looked for a bare 'i' with strchr(). That runs after optalias_check() has expanded the long aliases, so --build-top-index (-%i) and --protocol N (-@in) matched too: they wiped the URL list and left the run on the usage screen, exit 255. The neighbouring 'q' test had the same flaw, with -%q silently forcing quiet mode. Look for the flag in plain short-option clusters only, so -i, -iC1, -iC2 and --continue keep forcing continue mode while prefixed options stay distinct. Closes #615 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Xavier Roche <roche@httrack.com>
The helper tested the second character only, which disagreed with the parser in both directions: it dropped continue mode for -%qi and -%Mi, where the trailing i does reach the main set, and it still mistook the i of -q%i for -i, leaving that spelling on the usage screen. Walk the cluster instead, letting %, &, @ and # take the letter after them into another set wherever they sit. & matters because the -& to -% rewrite only fires at position 0, so -q&i reaches the parser as-is. None of this is reachable through a documented option or an alias, which all place the prefix first; it keeps the helper honest against hand-written clusters. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Xavier Roche <roche@httrack.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
httrack <URL> --build-top-indexexits 255 on the usage screen instead of crawling. The pass inhtscoremain.cthat counts URLs also detects-i(continue), and it looked for a bareiwithstrchr()on anythingcmdl_opt()calls an option. That test runs afteroptalias_check()has expanded the long aliases, so--build-top-index(-%i) and--protocol N(-@iN) matched the letter and wiped the URL list. The neighbouringstrchr(..., 'q')has the same flaw, where-%q/--include-query-stringquietly forces quiet mode.The flag is now found by walking the cluster the way the parser does (
htscoremain.c:948):%,&,@and#each take the letter after them into another option set, whatever their position, so theiof-%iis not the main-set-iwhile the one in-%Mistill is.&is on that list because the-&to-%rewrite only fires at position 0, leaving-q&ito reach the parser as-is. Testing the second character alone was not enough: it dropped continue mode for-%qiand-%Miand left-q%ion the usage screen. No documented option or alias reaches those spellings, since they all put the prefix first, but the helper agrees with the parser now.-i,-iC1,-iC2,--continueand--updatekeep forcing continue and dropping the URL list exactly as they do today.I went through the alias table rather than patching the two spellings I had:
-i,-iC1and-iC2are the intended matches,-%iand-@ithe broken ones. The rule only runs one way,argv_url = -1when the user asked to continue. The reverse has never held and still does not, becausecmdl_opt()'s heuristic hands a filter like-imagedirto the same branch. Filters carrying a.,/or*were never in scope.Tests go in the existing offline
01_engine-cmdline.test. Six cases fail on master and pass here, and the continue guards look for the usage screen rather than any nonzero exit, so they show continue mode was actually entered. They discriminate in both directions: the second-character helper fails four of them,-q%iand-q@ifor the bug plus-%qiand-%Mifor the regression, and mutating the helper to always return false fires the-iguard. The-%qcase has no teeth and I left it labelled that way. A run whose stdout is not a tty is forced quiet before argv parsing (htscoremain.c:174), so the suite cannot see that flag at all. I checked that half under a pty instead, where master-%qprints usage and this branch opens the wizard, with-qand-%g0as controls.Closes #615