From 27e82186d52f56e627344ebfe0833c3c915a3652 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon <pingou@pingoured.fr>
Date: Feb 10 2016 10:54:51 +0000
Subject: [PATCH 1/3] Fix deleting a branch with a '/' in its name


---

diff --git a/pagure/templates/repo_info.html b/pagure/templates/repo_info.html
index 96a1137..b8584c5 100644
--- a/pagure/templates/repo_info.html
+++ b/pagure/templates/repo_info.html
@@ -224,7 +224,7 @@ git push -u origin master</pre>
               {% endif %}
 
             {% for branch in branches if branch != head%}
-              <div id="branch-{{branch}}" class="repoinfo-branchlistitem row">
+              <div id="branch-{{ branch }}" class="repoinfo-branchlistitem row">
                 <div class="branch_name col-md-8">
                   <span class="oi text-muted" data-glyph="random"></span>
                   {% if branchname != branch %}
@@ -240,14 +240,14 @@ git push -u origin master</pre>
                 </div>
                 <div class="branch_del col-md-4">
                   {% if repo_admin and branch != head %}
-                  <form id="delete_branch_form-{{ branch }}" action="{{
+                  <form id="delete_branch_form-{{ branch | replace('/', '_') }}" action="{{
                     url_for('.delete_branch',
                             username=username, repo=repo.name, branchname=branch)
                     }}" method="post" class="inline icon del_icon"
                     onsubmit="return confirm('Are you sure you want to remove the branch: {{ branch }}?\nThis cannot be un-done!');">
                     {{ form.csrf_token }}
                     <a title="Remove branch {{ branch }}" href="#"
-                      onclick="$('#delete_branch_form-{{ branch }}').submit();">
+                      onclick="$('#delete_branch_form-{{ branch | replace('/', '_') }}').submit();">
                       <span class="oi" data-glyph="trash"></span>
                     </a>
                   </form>

From f8ff28a164f88bd1127ea3b5199d73968aaf5c77 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon <pingou@pingoured.fr>
Date: Feb 10 2016 14:35:15 +0000
Subject: [PATCH 2/3] Add unit-tests ensuring deleting a branch containing a '/' works


---

diff --git a/tests/test_pagure_flask_ui_repo.py b/tests/test_pagure_flask_ui_repo.py
index 0064ef8..98acaa6 100644
--- a/tests/test_pagure_flask_ui_repo.py
+++ b/tests/test_pagure_flask_ui_repo.py
@@ -2266,6 +2266,32 @@ index 0000000..fb7093d
                 '<a class="dropdown-item" href="/test/branch/master">',
                 output.data)
 
+            # Add a branch with a '/' in its name that we can delete
+            path = os.path.join(tests.HERE, 'test.git')
+            tests.add_content_git_repo(path)
+            repo = pygit2.Repository(path)
+            repo.create_branch('feature/foo', repo.head.get_object())
+
+            # Check before deletion
+            output = self.app.post('/test', follow_redirects=True)
+            self.assertEqual(output.status_code, 200)
+            self.assertIn(
+                '<a class="dropdown-item" href="/test/branch/feature/foo">',
+                output.data)
+            self.assertIn(
+                '<a class="dropdown-item" href="/test/branch/master">',
+                output.data)
+
+            # Delete the branch
+            output = self.app.post('/test/feature/foo/delete', follow_redirects=True)
+            self.assertEqual(output.status_code, 200)
+            self.assertNotIn(
+                '<a class="dropdown-item" href="/test/branch/feature/foo">',
+                output.data)
+            self.assertIn(
+                '<a class="dropdown-item" href="/test/branch/master">',
+                output.data)
+
     def test_view_docs(self):
         """ Test the view_docs endpoint. """
         output = self.app.get('/docs/foo/')

From 2623d50e25fdc771f5130e76c028d13ad0f119ee Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon <pingou@pingoured.fr>
Date: Feb 10 2016 14:37:53 +0000
Subject: [PATCH 3/3] Check that the form to delete the branch has the proper id


---

diff --git a/tests/test_pagure_flask_ui_repo.py b/tests/test_pagure_flask_ui_repo.py
index 98acaa6..4a518f5 100644
--- a/tests/test_pagure_flask_ui_repo.py
+++ b/tests/test_pagure_flask_ui_repo.py
@@ -2252,6 +2252,7 @@ index 0000000..fb7093d
             self.assertIn(
                 '<a class="dropdown-item" href="/test/branch/foo">',
                 output.data)
+            self.assertIn('<form id="delete_branch_form-foo"', output.data)
             self.assertIn(
                 '<a class="dropdown-item" href="/test/branch/master">',
                 output.data)
@@ -2262,6 +2263,8 @@ index 0000000..fb7093d
             self.assertNotIn(
                 '<a class="dropdown-item" href="/test/branch/foo">',
                 output.data)
+            self.assertNotIn(
+                '<form id="delete_branch_form-foo"', output.data)
             self.assertIn(
                 '<a class="dropdown-item" href="/test/branch/master">',
                 output.data)
@@ -2279,6 +2282,8 @@ index 0000000..fb7093d
                 '<a class="dropdown-item" href="/test/branch/feature/foo">',
                 output.data)
             self.assertIn(
+                '<form id="delete_branch_form-feature_foo"', output.data)
+            self.assertIn(
                 '<a class="dropdown-item" href="/test/branch/master">',
                 output.data)
 
@@ -2288,6 +2293,8 @@ index 0000000..fb7093d
             self.assertNotIn(
                 '<a class="dropdown-item" href="/test/branch/feature/foo">',
                 output.data)
+            self.assertNotIn(
+                '<form id="delete_branch_form-feature_foo"', output.data)
             self.assertIn(
                 '<a class="dropdown-item" href="/test/branch/master">',
                 output.data)

