View Issue Details

IDProjectCategoryView StatusLast Update
0035132FPCFCLpublic2019-04-03 13:50
ReporterBart Broersma Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformi386OSWindows 
Product Version3.3.1 
Target Version3.2.0Fixed in Version3.3.1 
Summary0035132: TRegistry.DeleteKey inconsistent behaviour Windows vs other platforms
DescriptionOn non-windows platforms TRegistry uses a TXMLRegistry.
If you use DeleteKey(Key) on Wondows it will only delete Key if Key has no subkeys.
The XML implementation however hapilly removes the Key including all subkeys.
Steps To ReproduceBuild and run attached example.
Expected output: EAssertionFailed: DeleteKey('One') failed. (delkey.pp, line 51)

On Linux however (an presumably all non-Windows platform it runs to the end.
And it will create the following xml:

<?xml version="1.0" encoding="utf-8"?>
<XMLReg>
  <Key Name="HKEY_CURRENT_USER">
    <Key Name="Software">
      <Key Name="TESTDELTREE">
        <Value Name="0" Type="2">0</Value>
      </Key>
    </Key>
  </Key>
</XMLReg>

TagsNo tags attached.
Fixed in Revision41817
FPCOldBugId
FPCTarget
Attached Files

Activities

Bart Broersma

2019-02-21 18:17

reporter  

delkey.pp (3,158 bytes)

Bart Broersma

2019-02-23 15:00

reporter  

xmlreg.deletekey.diff (856 bytes)   
Index: packages/fcl-registry/src/xmlreg.pp
===================================================================
--- packages/fcl-registry/src/xmlreg.pp	(revision 41415)
+++ packages/fcl-registry/src/xmlreg.pp	(working copy)
@@ -231,7 +231,8 @@
 Function TXmlRegistry.DeleteKey(KeyPath : String) : Boolean;
 
 Var
-  N : TDomElement;
+  N, Curr : TDomElement;
+  Node: TDOMNode;
 
 begin
  N:=FindKey(KeyPath);
@@ -238,6 +239,15 @@
  Result:=(N<>Nil);
  If Result then
    begin
+   //if a key has subkeys, result shall be false and nothing shall be deleted
+   Curr:=N;
+   Node:=Curr.FirstChild;
+   While Assigned(Node) do
+     begin
+     If (Node.NodeType=ELEMENT_NODE) and (Node.NodeName=SKey) then
+       Exit(False);
+     Node:=Node.NextSibling;
+     end;
    (N.ParentNode as TDomElement).RemoveChild(N);
    FDirty:=True;
    MaybeFlush;
xmlreg.deletekey.diff (856 bytes)   

Bart Broersma

2019-02-23 15:46

reporter  

tw35132.pp (1,822 bytes)

Bart Broersma

2019-02-23 15:48

reporter   ~0114367

Test tw35132.pp attached. Should go in tests/test/packages/fcl-registry.

Bart Broersma

2019-03-31 15:12

reporter  

xmlreg.deletekey.2.diff (863 bytes)   
Index: packages/fcl-registry/src/xmlreg.pp
===================================================================
--- packages/fcl-registry/src/xmlreg.pp	(revision 41788)
+++ packages/fcl-registry/src/xmlreg.pp	(working copy)
@@ -234,7 +234,8 @@
 Function TXmlRegistry.DeleteKey(KeyPath : UnicodeString) : Boolean;
 
 Var
-  N : TDomElement;
+  N, Curr : TDomElement;
+  Node: TDOMNode;
 
 begin
  N:=FindKey(KeyPath);
@@ -241,6 +242,15 @@
  Result:=(N<>Nil);
  If Result then
    begin
+   //if a key has subkeys, result shall be false and nothing shall be deleted
+   Curr:=N;
+   Node:=Curr.FirstChild;
+   While Assigned(Node) do
+     begin
+     If (Node.NodeType=ELEMENT_NODE) and (Node.NodeName=SKey) then
+       Exit(False);
+     Node:=Node.NextSibling;
+     end;
    (N.ParentNode as TDomElement).RemoveChild(N);
    FDirty:=True;
    MaybeFlush;
xmlreg.deletekey.2.diff (863 bytes)   

Bart Broersma

2019-03-31 15:12

reporter   ~0115146

Attached xmlreg.deletekey.2.diff: regenrated the patch after the massive changes of r41784.

Michael Van Canneyt

2019-04-01 17:16

administrator   ~0115169

Applied, thank you for the patch.

I converted your test program to a unit test using fpcunit.
Maybe in future also add tests to the test program in the tests directory.

Issue History

Date Modified Username Field Change
2019-02-21 18:17 Bart Broersma New Issue
2019-02-21 18:17 Bart Broersma File Added: delkey.pp
2019-02-23 15:00 Bart Broersma File Added: xmlreg.deletekey.diff
2019-02-23 15:46 Bart Broersma File Added: tw35132.pp
2019-02-23 15:48 Bart Broersma Note Added: 0114367
2019-03-31 15:12 Bart Broersma File Added: xmlreg.deletekey.2.diff
2019-03-31 15:12 Bart Broersma Note Added: 0115146
2019-04-01 17:16 Michael Van Canneyt Fixed in Revision => 41817
2019-04-01 17:16 Michael Van Canneyt Note Added: 0115169
2019-04-01 17:16 Michael Van Canneyt Status new => resolved
2019-04-01 17:16 Michael Van Canneyt Fixed in Version => 3.3.1
2019-04-01 17:16 Michael Van Canneyt Resolution open => fixed
2019-04-01 17:16 Michael Van Canneyt Assigned To => Michael Van Canneyt
2019-04-01 17:16 Michael Van Canneyt Target Version => 3.2.0
2019-04-03 13:50 Bart Broersma Status resolved => closed