Repository: Zaryob/iksemel (language: python)

Issue:
Merge from "dev"



Discussion / hints:

Fix patch:
diff --git a/.github/workflows/iksemel_basic.yml b/.github/workflows/iksemel_basic.yml
index 48be009..f2ffb1b 100755
--- a/.github/workflows/iksemel_basic.yml
+++ b/.github/workflows/iksemel_basic.yml
@@ -36,7 +36,7 @@ jobs:
       if: failure()
       run: |
           cat /home/runner/work/iksemel/iksemel/build/meson-logs/meson-log.txt
-    - uses: actions/upload-artifact@v2
+    - uses: actions/upload-artifact@v4
       if: failure()
       with:
         name: Logs
diff --git a/.github/workflows/iksemel_gnutls.yml b/.github/workflows/iksemel_gnutls.yml
index 65b5894..69c941d 100755
--- a/.github/workflows/iksemel_gnutls.yml
+++ b/.github/workflows/iksemel_gnutls.yml
@@ -33,7 +33,7 @@ jobs:
       if: failure()
       run: |
           cat /home/runner/work/iksemel/iksemel/build/meson-logs/meson-log.txt
-    - uses: actions/upload-artifact@v2
+    - uses: actions/upload-artifact@v4
       if: failure()
       with:
         name: Logs
diff --git a/.github/workflows/iksemel_openssl.yml b/.github/workflows/iksemel_openssl.yml
index 80fe50a..a52ee9f 100644
--- a/.github/workflows/iksemel_openssl.yml
+++ b/.github/workflows/iksemel_openssl.yml
@@ -33,7 +33,7 @@ jobs:
       if: failure()
       run: |
           cat /home/runner/work/iksemel/iksemel/build/meson-logs/meson-log.txt
-    - uses: actions/upload-artifact@v2
+    - uses: actions/upload-artifact@v4
       if: failure()
       with:
         name: Logs
diff --git a/.github/workflows/iksemel_python.yml b/.github/workflows/iksemel_python.yml
index 74d0abf..e5a830b 100644
--- a/.github/workflows/iksemel_python.yml
+++ b/.github/workflows/iksemel_python.yml
@@ -32,7 +32,7 @@ jobs:
       if: failure()
       run: |
           cat /home/runner/work/iksemel/iksemel/build/meson-logs/meson-log.txt
-    - uses: actions/upload-artifact@v2
+    - uses: actions/upload-artifact@v4
       if: failure()
       with:
         name: Logs
diff --git a/ChangeLog b/ChangeLog
index c4b5ae8..edc7355 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+2024-08-12 Zaryob
+  * uchar.h independent utf-8 decoding.
+
 2020-06-12 Zaryob
   * All building structure chaned with meson build tools.
 
diff --git a/README.md b/README.md
index b85c133..d0ffa8c 100644
--- a/README.md
+++ b/README.md
@@ -2,15 +2,15 @@
 
 [![Travis Status](https://travis-ci.org/Zaryob/iksemel.svg?branch=master)](https://travis-ci.org/Zaryob/iksemel) ![Language](https://img.shields.io/badge/language-c-blue.svg) ![License](https://img.shields.io/badge/license-LGPL2-purple.svg) [![Document](https://img.shields.io/badge/document-gh--pages-blue)](https://zaryob.github.io/iksemels)
 
-                      iksemel 1.6.1
+                      iksemel 1.6.2
 
             http://code.google.com/p/iksemel
 
-Owner:
-Copyright (c) 2000-2011 Gurer Ozen <meduketto at gmail.com>
+      Owner:
+      Copyright (c) 2000-2011 Gurer Ozen <meduketto at gmail.com>
 
-Changes and adaptations:
-Copyright (c) 2016-2022 Suleyman Poyraz <zaryob.dev at gmail.com>
+      Changes and maintenance:
+      Copyright (c) 2016-2024 Suleyman Poyraz <zaryob.dev at gmail.com>
 
 Introduction:
 -------------
@@ -36,23 +36,25 @@ Compiling & Install:
 --------------------
 
 If you got the source from CVS, type
-
+```bash
   meson build
-
+```
 for creating configuration script and files.
 
 Then type
-
+```bash
   ninja -C build
-
+```
 now library is compiled. You can test it with
-
+```bash
   ninja test -C build
-
+```
 and install it with
 
   (become root if necessary)
+```bash
   ninja install -C build
+```
 
 Parameters
 ----------
diff --git a/pyproject.toml b/pyproject.toml
index 68389bb..10c438f 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
 [project]
 name = "iksemel"
-version = "1.6.1"
+version = "1.6.2"
 authors = [
   { name="Suleyman Poyraz", email="zaryob.dev@gmail.com" },
 ]
diff --git a/setup.py b/setup.py
index 6414b02..9ba29ee 100644
--- a/setup.py
+++ b/setup.py
@@ -17,7 +17,7 @@
 from distutils.core import setup, Extension
 from distutils.command.install import install
 
-version = '1.6.1'
+version = '1.6.2'
 
 distfiles = """
     README
diff --git a/src/dom.c b/src/dom.c
index 37087aa..1aab15b 100644
--- a/src/dom.c
+++ b/src/dom.c
@@ -16,27 +16,32 @@ struct dom_data {
 static int
 tagHook (struct dom_data *data, char *name, char **atts, int type)
 {
-	iks *x;
+	iks* x;
 
 	if (IKS_OPEN == type || IKS_SINGLE == type) {
 		if (data->current) {
-			x = iks_insert (data->current, name);
-		} else {
-			ikstack *s;
-			s = iks_stack_new (data->chunk_size, data->chunk_size);
-			x = iks_new_within (name, s);
+			x = iks_insert(data->current, name);
+		}
+		else {
+			ikstack* s;
+			s = iks_stack_new(data->chunk_size, data->chunk_size);
+			x = iks_new_within(name, s);
+			if (!x) {
+				iks_stack_delete (s);
+				return IKS_NOMEM;
+			}
 		}
 		if (atts) {
-			int i=0;
+			int i = 0;
 			while (atts[i]) {
-				iks_insert_attrib (x, atts[i], atts[i+1]);
+				iks_insert_attrib(x, atts[i], atts[i + 1]);
 				i += 2;
 			}
 		}
 		data->current = x;
 	}
 	if (IKS_CLOSE == type || IKS_SINGLE == type) {
-		x = iks_parent (data->current);
+		x = iks_parent(data->current);
 		if (iks_strcmp(iks_name(data->current), name) != 0)
 			return IKS_BADXML;
 		if (x)
@@ -141,6 +146,7 @@ iks_load (const char *fname, iks **xptr)
 					int e;
 					e = iks_parse (prs, buf, len, done);
 					if (IKS_OK != e) {
+						iks_parser_delete (prs);
 						ret = e;
 						break;
 					}
diff --git a/src/iks.c b/src/iks.c
index db336d7..cc4439a 100644
--- a/src/iks.c
+++ b/src/iks.c
@@ -803,9 +803,9 @@ iks_string (ikstack *s, iks *x)
 					*t++ = ' ';
 					t = my_strcat (t, IKS_ATTRIB_NAME (y), 0);
 					*t++ = '=';
-					*t++ = '\'';
+					*t++ = '"';
 					t = escape (t, IKS_ATTRIB_VALUE (y), strlen (IKS_ATTRIB_VALUE (y)));
-					*t++ = '\'';
+					*t++ = '"';
 					y = y->next;
 				}
 				if (IKS_TAG_CHILDREN (x)) {
diff --git a/src/sax.c b/src/sax.c
index a6c0ba3..7d55042 100644
--- a/src/sax.c
+++ b/src/sax.c
@@ -339,7 +339,10 @@ sax_core (iksparser *prs, char *buf, int len)
 					char **tmp;
 					if (prs->attcur == 0) tmp = NULL; else tmp = prs->atts;
 					err = prs->tagHook (prs->user_data, prs->tag_name, tmp, prs->tagtype);
-					if (IKS_OK != err) return err;
+					if (IKS_OK != err) {
+						iks_free(prs->atts);
+						return err;
+					}
 				}
 				prs->stack_pos = 0;
 				stack_old = -1;
@@ -374,7 +377,7 @@ sax_core (iksparser *prs, char *buf, int len)
 						if (!tmp) return IKS_NOMEM;
 						memset (tmp, 0, sizeof(char *) * 2 * prs->attmax);
 						memcpy (tmp, prs->atts, sizeof(char *) * prs->attcur);
-						free (prs->atts);
+						iks_free(prs->atts);
 						prs->atts = tmp;
 					}
 				}


Test patch:
diff --git a/python/test/attibutes.py b/python/test/attibutes.py
index e37b679..b54726c 100755
--- a/python/test/attibutes.py
+++ b/python/test/attibutes.py
@@ -2,7 +2,7 @@
 
 import iksemel as iks
 
-doc_xml = "<lala b='' c='42'/>"
+doc_xml = "<lala b=\"\" c=\"42\"/>"
 
 doc = iks.newDocument("lala")
 doc.setAttribute("a", "lala")
diff --git a/python/test/generate.py b/python/test/generate.py
index 5e23dc0..efb88eb 100755
--- a/python/test/generate.py
+++ b/python/test/generate.py
@@ -5,7 +5,7 @@
 doc_xml = """
 <test>
     <a><b><c/></b></a>
-    <item foo='lala'>
+    <item foo="lala">
         <tuktuk>blah &amp; bleh</tuktuk>
         <nanuk/>
     </item>
@@ -58,7 +58,7 @@
 b.setAttribute("lal", "foo")
 b = doc.insertNode(b)
 b.setAttribute("lal", "foofff")
-assert(doc.toString() == "<a><b lal='foofff'/></a>")
+assert(doc.toString() == "<a><b lal=\"foofff\"/></a>")
 
 # now with append, prepend and insertNode
 
diff --git a/test/tst-dom.c b/test/tst-dom.c
index ecd098a..a143018 100644
--- a/test/tst-dom.c
+++ b/test/tst-dom.c
@@ -31,11 +31,13 @@ document (char *xml)
 			break;
 		case IKS_NOMEM:
 			PR_TEST;
+			iks_parser_delete(p);
 			puts ("Not enough memory.");
 			exit (1);
 		case IKS_BADXML:
 			PR_TEST;
 			printf ("Invalid xml at byte %ld in\n[%s]\n", iks_nr_bytes (p), xml);
+			iks_parser_delete(p);
 			exit (1);
 		case IKS_HOOK:
 			PR_TEST;
@@ -44,6 +46,10 @@ document (char *xml)
 	iks_parser_delete (p);
 }
 
+void finalize() {
+	if (my_x) iks_delete(my_x);
+}
+
 void
 tag (char *name, ...)
 {
@@ -140,8 +146,8 @@ string (char *xml)
 }
 
 static char buf[] =
-	"<presence id='JCOM_11' to='lala@j.org' type='available'><status>"
-	"&quot; &lt;online&amp;dangerous&gt; &quot;</status>meow<a><b c='d'/>"
+	"<presence id=\"JCOM_11\" to=\"lala@j.org\" type=\"available\"><status>"
+	"&quot; &lt;online&amp;dangerous&gt; &quot;</status>meow<a><b c=\"d\"/>"
 	"</a><test/></presence>";
 
 int main (int argc, char *argv[])
@@ -160,5 +166,6 @@ int main (int argc, char *argv[])
 	tag ("test", 0);
 	string (buf);
 
+	finalize();
 	return 0;
 }
diff --git a/test/tst-iks.c b/test/tst-iks.c
index daa5f87..0a3e7a7 100644
--- a/test/tst-iks.c
+++ b/test/tst-iks.c
@@ -14,8 +14,8 @@
 int main (int argc, char *argv[])
 {
 	static char xml[] =
-		"<iq type='result' to='ydobon@jabber.org'><query xmlns='jabber:iq:version'>"
-		"<name>TestClient</name><os>SuxOS 2000</os><version><stable solidity='rock'/>"
+		"<iq type=\"result\" to=\"ydobon@jabber.org\"><query xmlns=\"jabber:iq:version\">"
+		"<name>TestClient</name><os>SuxOS 2000</os><version><stable solidity=\"rock\"/>"
 		"1.2.0 patchlevel 2</version></query></iq>";
 	static char xml2[] =
 		"<Ni><C/>lala<br/><A/>Hello World<B/></Ni>";
diff --git a/test/tst-sax.c b/test/tst-sax.c
index 0c0fbba..9b34a38 100644
--- a/test/tst-sax.c
+++ b/test/tst-sax.c
@@ -230,12 +230,15 @@ test_size (int blocksize)
 			case IKS_OK:
 				break;
 			case IKS_NOMEM:
+				iks_parser_delete(prs);
 				exit (1);
 			case IKS_BADXML:
 				PRINT_TEST;
 				printf ("Invalid xml at byte %ld in\n[%s]\n", iks_nr_bytes (prs), tester.doc);
+				iks_parser_delete(prs);
 				exit (1);
 			case IKS_HOOK:
+				iks_parser_delete(prs);
 				exit (1);
 		}
 		i += blocksize;
@@ -266,13 +269,19 @@ test_bad (int badbyte)
 		case IKS_OK:
 			break;
 		case IKS_NOMEM:
+			iks_parser_delete(p);
 			exit (1);
 		case IKS_BADXML:
-			if (iks_nr_bytes (p) == badbyte) return;
+			if (iks_nr_bytes (p) == badbyte) {
+				iks_parser_delete(p);
+				return;
+			}
 			break;
 		case IKS_HOOK:
+			iks_parser_delete(p);
 			exit (1);
 	}
+	iks_parser_delete(p);
 	printf ("Sax test %d:\n", tester.nr_tests);
 	printf ("Expected bad byte %d, got %ld in\n[%s]\n", badbyte, iks_nr_bytes (p), tester.doc);
 	exit (1);