Fossil SCM

In the new HOST:PATH extension to "diff --tk" (check-in [3daa780e2ccd1d04]), make sure that the HOST:PATH argument is not a valid argument to an options like --from or --to or similar.

drh 2026-08-11 17:11 UTC trunk
Commit 2c72fb8742493fedc7b69fc7667daa8585b5949102ba73649f4f742a111426d8
1 file changed +24
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -1212,10 +1212,33 @@
12121212
blob_appendf(pBlob, "\\%03o", (unsigned char)z[j]);
12131213
}
12141214
}
12151215
}
12161216
}
1217
+
1218
+/*
1219
+** Return TRUE (non-zero) if zArg is a valid option to "diff" or
1220
+** "gdiff" that takes an argument that might be confused for a
1221
+** HOST:PATH or USER@HOST:PATH filename.
1222
+*/
1223
+static int isDiffOptionWithArg(const char *zArg){
1224
+ int i;
1225
+ const char *az[] = {
1226
+ "binary",
1227
+ "branch",
1228
+ "ci", "checkin",
1229
+ "r", "from",
1230
+ "to"
1231
+ };
1232
+ if( zArg[0]!='-' ) return 0;
1233
+ zArg++;
1234
+ if( zArg[0]=='-' ) zArg++;
1235
+ for(i=0; i<count(az); i++){
1236
+ if( fossil_strcmp(zArg, az[i])==0 ) return 1;
1237
+ }
1238
+ return 0;
1239
+}
12171240
12181241
/*
12191242
** Show diff output in a Tcl/Tk window, in response to the --tk option
12201243
** to the diff command.
12211244
**
@@ -1260,10 +1283,11 @@
12601283
** for testing and debugging. */
12611284
zTempFile = find_option("script",0,1);
12621285
for(i=firstArg; i<g.argc; i++){
12631286
const char *z = g.argv[i];
12641287
if( zHost==0
1288
+ && (i==firstArg || !isDiffOptionWithArg(g.argv[i-1]))
12651289
&& !file_isfile_or_link(z)
12661290
&& (zDir = file_skip_userhost(z))!=0
12671291
){
12681292
zHost = mprintf("%.*s", (int)(zDir - z - 1), z);
12691293
continue;
12701294
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -1212,10 +1212,33 @@
1212 blob_appendf(pBlob, "\\%03o", (unsigned char)z[j]);
1213 }
1214 }
1215 }
1216 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1217
1218 /*
1219 ** Show diff output in a Tcl/Tk window, in response to the --tk option
1220 ** to the diff command.
1221 **
@@ -1260,10 +1283,11 @@
1260 ** for testing and debugging. */
1261 zTempFile = find_option("script",0,1);
1262 for(i=firstArg; i<g.argc; i++){
1263 const char *z = g.argv[i];
1264 if( zHost==0
 
1265 && !file_isfile_or_link(z)
1266 && (zDir = file_skip_userhost(z))!=0
1267 ){
1268 zHost = mprintf("%.*s", (int)(zDir - z - 1), z);
1269 continue;
1270
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -1212,10 +1212,33 @@
1212 blob_appendf(pBlob, "\\%03o", (unsigned char)z[j]);
1213 }
1214 }
1215 }
1216 }
1217
1218 /*
1219 ** Return TRUE (non-zero) if zArg is a valid option to "diff" or
1220 ** "gdiff" that takes an argument that might be confused for a
1221 ** HOST:PATH or USER@HOST:PATH filename.
1222 */
1223 static int isDiffOptionWithArg(const char *zArg){
1224 int i;
1225 const char *az[] = {
1226 "binary",
1227 "branch",
1228 "ci", "checkin",
1229 "r", "from",
1230 "to"
1231 };
1232 if( zArg[0]!='-' ) return 0;
1233 zArg++;
1234 if( zArg[0]=='-' ) zArg++;
1235 for(i=0; i<count(az); i++){
1236 if( fossil_strcmp(zArg, az[i])==0 ) return 1;
1237 }
1238 return 0;
1239 }
1240
1241 /*
1242 ** Show diff output in a Tcl/Tk window, in response to the --tk option
1243 ** to the diff command.
1244 **
@@ -1260,10 +1283,11 @@
1283 ** for testing and debugging. */
1284 zTempFile = find_option("script",0,1);
1285 for(i=firstArg; i<g.argc; i++){
1286 const char *z = g.argv[i];
1287 if( zHost==0
1288 && (i==firstArg || !isDiffOptionWithArg(g.argv[i-1]))
1289 && !file_isfile_or_link(z)
1290 && (zDir = file_skip_userhost(z))!=0
1291 ){
1292 zHost = mprintf("%.*s", (int)(zDir - z - 1), z);
1293 continue;
1294

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button