Fixed text updating for UTF-8 strings.
authorŁukasz Rekucki <lrekucki@gmail.com>
Sat, 26 Sep 2009 17:30:58 +0000 (19:30 +0200)
committerŁukasz Rekucki <lrekucki@gmail.com>
Sat, 26 Sep 2009 17:30:58 +0000 (19:30 +0200)
apps/api/handlers/library_handlers.py
lib/wlrepo/mercurial_backend/__init__.py
lib/wlrepo/mercurial_backend/document.py
lib/wlrepo/mercurial_backend/library.py

index 552eb6f..5f844db 100644 (file)
@@ -143,9 +143,9 @@ class DocumentHandler(BaseHandler):
 
         result = {
             'name': udoc.id,
 
         result = {
             'name': udoc.id,
-            'html_url': reverse('dochtml_view', args=[doc.id,doc.revision]),
-            'text_url': reverse('doctext_view', args=[doc.id,doc.revision]),
-            'dc_url': reverse('docdc_view', args=[doc.id,doc.revision]),
+            'html_url': reverse('dochtml_view', args=[udoc.id,udoc.revision]),
+            'text_url': reverse('doctext_view', args=[udoc.id,udoc.revision]),
+            'dc_url': reverse('docdc_view', args=[udoc.id,udoc.revision]),
             'user_revision': udoc.revision,
             'public_revision': doc.revision,            
         }       
             'user_revision': udoc.revision,
             'public_revision': doc.revision,            
         }       
@@ -215,15 +215,19 @@ class DocumentTextHandler(BaseHandler):
                         "provided_revision": orig.revision,
                         "latest_revision": current.revision })
 
                         "provided_revision": orig.revision,
                         "latest_revision": current.revision })
 
-            ndoc = doc.quickwrite('xml', data, msg)
+            ndoc = current.quickwrite('xml', data, msg)
 
 
-            # return the new revision number
-            return {
-                "document": ndoc.id,
-                "subview": "xml",
-                "previous_revision": prev,
-                "updated_revision": ndoc.revision
-            }
+            try:
+                # return the new revision number
+                return {
+                    "document": ndoc.id,
+                    "subview": "xml",
+                    "previous_revision": current.revision,
+                    "updated_revision": ndoc.revision
+                }
+            except Exception, e:
+                lib.rollback()
+                raise e
         
         except (RevisionNotFound, KeyError):
             return response.EntityNotFound().django_response()
         
         except (RevisionNotFound, KeyError):
             return response.EntityNotFound().django_response()
index 2815881..c1d3d30 100644 (file)
@@ -20,7 +20,7 @@ class MercurialRevision(wlrepo.Revision):
             idx = branchname.find("$doc:")
             if(idx < 0):
                 raise ValueError("Revision %s is not a valid document revision." % changectx.hex());
             idx = branchname.find("$doc:")
             if(idx < 0):
                 raise ValueError("Revision %s is not a valid document revision." % changectx.hex());
-            self._username = branchname[0:idx]
+            self._username = branchname[6:idx]
             self._docname = branchname[idx+5:]
         else:
             raise ValueError("Revision %s is not a valid document revision." % changectx.hex());
             self._docname = branchname[idx+5:]
         else:
             raise ValueError("Revision %s is not a valid document revision." % changectx.hex());
index c7f2f9f..6cf8a5b 100644 (file)
@@ -15,6 +15,14 @@ class MercurialDocument(wlrepo.Document):
 
     def quickwrite(self, entry, data, msg, user=None):
         user = user or self.owner
 
     def quickwrite(self, entry, data, msg, user=None):
         user = user or self.owner
+
+        if isinstance(data, unicode):
+            data = data.encode('utf-8')
+            
+        user = self._library._sanitize_string(user)
+        msg = self._library._sanitize_string(msg)
+        entry = self._library._sanitize_string(entry)
+
         if user is None:
             raise ValueError("Can't determine user.")
         
         if user is None:
             raise ValueError("Can't determine user.")
         
@@ -38,7 +46,12 @@ class MercurialDocument(wlrepo.Document):
             ops(self._library, entry_path)
             message, user = before_commit(self)            
             self._library._commit(message, user)
             ops(self._library, entry_path)
             message, user = before_commit(self)            
             self._library._commit(message, user)
-            return self._library.document(docid=self.id, user=self.owner)       
+            try:
+                return self._library.document(docid=self.id, user=user)
+            except Exception, e:
+                # rollback the last commit
+                self._library.rollback()
+                raise e
         finally:
             lock.release()
         
         finally:
             lock.release()
         
index 82b5263..7a33bf3 100644 (file)
@@ -255,9 +255,6 @@ class MercurialLibrary(wlrepo.Library):
             return None
 
         if isinstance(s, unicode):
             return None
 
         if isinstance(s, unicode):
-            s = s.encode('utf-8')
-
-        if ' ' in s:
-            raise ValueError('Whitespace is forbidden!')
+            s = s.encode('utf-8')        
 
         return s
\ No newline at end of file
 
         return s
\ No newline at end of file