Fossil SCM
Fix for problem reported at [https://fossil-scm.org/forum/forumpost/e4953666d6] which triggered a JSON-mode assertion when trying to access a /json path via a server running in directory-serving mode (which prefixes such paths with the repo name). Such paths are now recognized as routes into the JSON API.
Commit
dd490d17bec777c4cc26aecfa672d8c29a69292e7c867558023549c11322c553
Parent
4a880a166ae0bb7…
1 file changed
+20
-4
+20
-4
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -1579,14 +1579,30 @@ | ||
| 1579 | 1579 | ** process JSON-mode POST data if we're actually in a /json |
| 1580 | 1580 | ** page). This is normally set up before this routine is called, but |
| 1581 | 1581 | ** it looks like the ssh_request_loop() approach to dispatching |
| 1582 | 1582 | ** might bypass that. |
| 1583 | 1583 | */ |
| 1584 | - if( g.json.isJsonMode==0 && zPathInfo!=0 | |
| 1585 | - && 0==strncmp("/json",zPathInfo,5) | |
| 1586 | - && (zPathInfo[5]==0 || zPathInfo[5]=='/')){ | |
| 1587 | - g.json.isJsonMode = 1; | |
| 1584 | + if( g.json.isJsonMode==0 && zPathInfo!=0 ){ | |
| 1585 | + if(0==strncmp("/json",zPathInfo,5) | |
| 1586 | + && (zPathInfo[5]==0 || zPathInfo[5]=='/')){ | |
| 1587 | + g.json.isJsonMode = 1; | |
| 1588 | + }else if(g.zCmdName!=0 && 0==strcmp("server",g.zCmdName)){ | |
| 1589 | + /* When running in server "directory" mode, zPathInfo is | |
| 1590 | + ** prefixed with the repository's name, so in order to determine | |
| 1591 | + ** whether or not we're really running in json mode we have to | |
| 1592 | + ** try a bit harder. Problem reported here: | |
| 1593 | + ** https://fossil-scm.org/forum/forumpost/e4953666d6 | |
| 1594 | + */ | |
| 1595 | + ReCompiled * pReg = 0; | |
| 1596 | + const char * zErr = re_compile(&pReg, "^/[^/]+/json(/.*)?", 0); | |
| 1597 | + assert(zErr==0 && "Regex compilation failed?"); | |
| 1598 | + if(zErr==0 && | |
| 1599 | + re_match(pReg, (const unsigned char *)zPathInfo, -1)){ | |
| 1600 | + g.json.isJsonMode = 1; | |
| 1601 | + } | |
| 1602 | + re_free(pReg); | |
| 1603 | + } | |
| 1588 | 1604 | } |
| 1589 | 1605 | #endif |
| 1590 | 1606 | /* If the repository has not been opened already, then find the |
| 1591 | 1607 | ** repository based on the first element of PATH_INFO and open it. |
| 1592 | 1608 | */ |
| 1593 | 1609 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -1579,14 +1579,30 @@ | |
| 1579 | ** process JSON-mode POST data if we're actually in a /json |
| 1580 | ** page). This is normally set up before this routine is called, but |
| 1581 | ** it looks like the ssh_request_loop() approach to dispatching |
| 1582 | ** might bypass that. |
| 1583 | */ |
| 1584 | if( g.json.isJsonMode==0 && zPathInfo!=0 |
| 1585 | && 0==strncmp("/json",zPathInfo,5) |
| 1586 | && (zPathInfo[5]==0 || zPathInfo[5]=='/')){ |
| 1587 | g.json.isJsonMode = 1; |
| 1588 | } |
| 1589 | #endif |
| 1590 | /* If the repository has not been opened already, then find the |
| 1591 | ** repository based on the first element of PATH_INFO and open it. |
| 1592 | */ |
| 1593 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -1579,14 +1579,30 @@ | |
| 1579 | ** process JSON-mode POST data if we're actually in a /json |
| 1580 | ** page). This is normally set up before this routine is called, but |
| 1581 | ** it looks like the ssh_request_loop() approach to dispatching |
| 1582 | ** might bypass that. |
| 1583 | */ |
| 1584 | if( g.json.isJsonMode==0 && zPathInfo!=0 ){ |
| 1585 | if(0==strncmp("/json",zPathInfo,5) |
| 1586 | && (zPathInfo[5]==0 || zPathInfo[5]=='/')){ |
| 1587 | g.json.isJsonMode = 1; |
| 1588 | }else if(g.zCmdName!=0 && 0==strcmp("server",g.zCmdName)){ |
| 1589 | /* When running in server "directory" mode, zPathInfo is |
| 1590 | ** prefixed with the repository's name, so in order to determine |
| 1591 | ** whether or not we're really running in json mode we have to |
| 1592 | ** try a bit harder. Problem reported here: |
| 1593 | ** https://fossil-scm.org/forum/forumpost/e4953666d6 |
| 1594 | */ |
| 1595 | ReCompiled * pReg = 0; |
| 1596 | const char * zErr = re_compile(&pReg, "^/[^/]+/json(/.*)?", 0); |
| 1597 | assert(zErr==0 && "Regex compilation failed?"); |
| 1598 | if(zErr==0 && |
| 1599 | re_match(pReg, (const unsigned char *)zPathInfo, -1)){ |
| 1600 | g.json.isJsonMode = 1; |
| 1601 | } |
| 1602 | re_free(pReg); |
| 1603 | } |
| 1604 | } |
| 1605 | #endif |
| 1606 | /* If the repository has not been opened already, then find the |
| 1607 | ** repository based on the first element of PATH_INFO and open it. |
| 1608 | */ |
| 1609 |