Patchwork [2,of,4] hgweb: add error template to json so it won't crash

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 7, 2018, 1:39 p.m.
Message ID <90fe6481af4fd42def15.1536327585@mimosa>
Download mbox | patch
Permalink /patch/34389/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 7, 2018, 1:39 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1536326368 -32400
#      Fri Sep 07 22:19:28 2018 +0900
# Node ID 90fe6481af4fd42def159f8e501612f305979822
# Parent  cd0c58017ae949408c1e746c9c81ca6847591b3c
hgweb: add error template to json so it won't crash

Patch

diff --git a/mercurial/templates/json/map b/mercurial/templates/json/map
--- a/mercurial/templates/json/map
+++ b/mercurial/templates/json/map
@@ -241,3 +241,6 @@  indexentry = '\{
   "lastchange": {lastchange|json},
   "labels": {labels|json}
   }'
+error = '\{
+  "error": {error|utf8|json}
+  }'
diff --git a/tests/test-hgweb-json.t b/tests/test-hgweb-json.t
--- a/tests/test-hgweb-json.t
+++ b/tests/test-hgweb-json.t
@@ -2183,6 +2183,16 @@  help/{topic} shows an individual help to
     "topic": "phases"
   }
 
+Error page shouldn't crash
+
+  $ request json-changeset/deadbeef
+  404 Not Found
+  
+  {
+    "error": "unknown revision 'deadbeef'"
+  }
+  [1]
+
 Commit message with Japanese Kanji 'Noh', which ends with '\x5c'
 
   $ echo foo >> da/foo