• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

CLI interface to medialist (fossil mirror)


Commit MetaInfo

Revision02fbb03cffc415f6ce44968d65646761afea14d2 (tree)
Zeit2023-03-09 14:50:21
Autormio <stigma@disr...>
Commitermio

Log Message

Fix ml_fetch_item with index 0 "finding" an item when it's not a valid item ID (d247886e46)

FossilOrigin-Name: 8494404e36d073561578a3ca7ddddee6c7bf7aea3d9b707940abf0e08a158611

Ändern Zusammenfassung

Diff

--- a/medialist.d
+++ b/medialist.d
@@ -747,6 +747,7 @@ MediaListItem ml_fetch_item(MediaList* list, size_t id)
747747 string line;
748748 size_t currentLine = 0;
749749 bool found = false;
750+ bool pastHeader = false;
750751
751752 while ((line = listFile.readln()) !is null) {
752753 if (0 >= line.length)
@@ -755,6 +756,13 @@ MediaListItem ml_fetch_item(MediaList* list, size_t id)
755756 if ('#' == line[0])
756757 continue;
757758
759+ /* First non-comment line in medialist mTSV file is header */
760+ if (false == pastHeader) {
761+ pastHeader = true;
762+ currentLine += 1;
763+ continue;
764+ }
765+
758766 if (id == currentLine) {
759767 found = true;
760768 break;
--- a/unittests.d
+++ b/unittests.d
@@ -947,3 +947,40 @@ unittest
947947 assert(items.length == 1, "Returned item array doesn't contain one item");
948948 assert(items[0].title == "Item 2", "First (idx:1 was idx:2) item title doesn't match.");
949949 }
950+
951+
952+/*
953+ * Ticket d247886e46
954+ *
955+ * Since all the commands expect a 1-based index (with medialist
956+ * automatically adjusting) passing an index of 0 should either set the
957+ * error to MLError.itemNotFound or throw an MLException -- depending
958+ * on whether it's the nothrow variant.
959+ *
960+ * Basically, there is an error when reading each line where we don't
961+ * check if we've past the header line.
962+ */
963+@(`ml_fetch_item doesn't work with index 0 (d247886e46)`)
964+unittest
965+{
966+ enum listName = __FUNCTION__;
967+ enum fileName = listName ~ ".tsv";
968+
969+ MediaList* list = ml_open_list(fileName);
970+ scope(exit) {
971+ ml_send_command(list, MLCommand.delete_, []);
972+ ml_free_list(list);
973+ }
974+
975+ MediaListItem item;
976+ MLError error;
977+
978+ item = ml_fetch_item(list, 0, error);
979+ assert(MLError.success != error,
980+ "ml_fetch_item with index 0 (0 items) returned \"successfully\" when expected error.");
981+
982+ ml_send_command(list, MLCommand.add, ["Item 1"]);
983+ item = ml_fetch_item(list, 0, error);
984+ assert(MLError.success != error,
985+ "ml_fetch_item with index 0 (1 item) returned \"successfully\" when expected error.");
986+}