bugfix: handle wrong date input in entry creation
This commit is contained in:
		@@ -27,10 +27,16 @@ BEGIN {
 | 
			
		||||
desc { desc = desc "\\n" $0; next; }
 | 
			
		||||
{
 | 
			
		||||
  from = substr($0, 1, 6) == "::: |>" ? substr($0, 8) : "";
 | 
			
		||||
  if (!from)
 | 
			
		||||
    exit 1
 | 
			
		||||
  getline
 | 
			
		||||
  to = substr($0, 1, 6) == "::: <|" ? substr($0, 8) : "";
 | 
			
		||||
  if (!to)
 | 
			
		||||
    exit 1
 | 
			
		||||
  getline
 | 
			
		||||
  summary = substr($0, 1, 2) == "# " ? substr($0, 3) : ""
 | 
			
		||||
  if (!summary)
 | 
			
		||||
    exit 1
 | 
			
		||||
  getline # This line should be empty
 | 
			
		||||
  getline # First line of description
 | 
			
		||||
  desc = $0;
 | 
			
		||||
@@ -41,7 +47,7 @@ END {
 | 
			
		||||
  # If nanoseconds are not 0, then we assume user enterd "tomorrow" or
 | 
			
		||||
  # something the like, and we make this a date entry, as opposed to a
 | 
			
		||||
  # date-time entry.
 | 
			
		||||
  from = from ? from : "now"
 | 
			
		||||
  gsub("\"", "\\\"", from)
 | 
			
		||||
  cmd = "date -d \"" from "\" +\"%N\"";
 | 
			
		||||
  cmd | getline t
 | 
			
		||||
  close(cmd)
 | 
			
		||||
@@ -53,10 +59,13 @@ END {
 | 
			
		||||
    from_type = "DATE"
 | 
			
		||||
    cmd = "date -d \"" from "\" +\"%Y%m%d\"";
 | 
			
		||||
  }
 | 
			
		||||
  cmd | getline from
 | 
			
		||||
  suc = cmd | getline from
 | 
			
		||||
  close(cmd)
 | 
			
		||||
  if (suc != 1) {
 | 
			
		||||
    exit 1
 | 
			
		||||
  }
 | 
			
		||||
  #
 | 
			
		||||
  to = to ? to : "now"
 | 
			
		||||
  gsub("\"", "\\\"", to)
 | 
			
		||||
  cmd = "date -d \"" to "\" +\"%N\"";
 | 
			
		||||
  cmd | getline t
 | 
			
		||||
  close(cmd)
 | 
			
		||||
@@ -68,8 +77,11 @@ END {
 | 
			
		||||
    to_type = "DATE"
 | 
			
		||||
    cmd = "date -d \"" to "\" +\"%Y%m%d\"";
 | 
			
		||||
  }
 | 
			
		||||
  cmd | getline to
 | 
			
		||||
  suc = cmd | getline to
 | 
			
		||||
  close(cmd)
 | 
			
		||||
  if (suc != 1) {
 | 
			
		||||
    exit 1
 | 
			
		||||
  }
 | 
			
		||||
  escape(summary);
 | 
			
		||||
  escape(desc);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -36,7 +36,7 @@ ENDFILE {
 | 
			
		||||
    # If nanoseconds are not 0, then we assume user enterd "tomorrow" or
 | 
			
		||||
    # something the like, and we make this a date entry, as opposed to a
 | 
			
		||||
    # date-time entry.
 | 
			
		||||
    from = from ? from : "now"
 | 
			
		||||
    gsub("\"", "\\\"", from)
 | 
			
		||||
    cmd = "date -d \"" from "\" +\"%N\"";
 | 
			
		||||
    cmd | getline t
 | 
			
		||||
    close(cmd)
 | 
			
		||||
@@ -48,10 +48,13 @@ ENDFILE {
 | 
			
		||||
      from_type = "DATE"
 | 
			
		||||
      cmd = "date -d \"" from "\" +\"%Y%m%d\"";
 | 
			
		||||
    }
 | 
			
		||||
    cmd | getline from
 | 
			
		||||
    suc = cmd | getline from
 | 
			
		||||
    close(cmd)
 | 
			
		||||
    if (suc != 1) {
 | 
			
		||||
      exit 1
 | 
			
		||||
    }
 | 
			
		||||
    #
 | 
			
		||||
    to = to ? to : "now"
 | 
			
		||||
    gsub("\"", "\\\"", to)
 | 
			
		||||
    cmd = "date -d \"" to "\" +\"%N\"";
 | 
			
		||||
    cmd | getline t
 | 
			
		||||
    close(cmd)
 | 
			
		||||
@@ -63,20 +66,29 @@ ENDFILE {
 | 
			
		||||
      to_type = "DATE"
 | 
			
		||||
      cmd = "date -d \"" to "\" +\"%Y%m%d\"";
 | 
			
		||||
    }
 | 
			
		||||
    cmd | getline to
 | 
			
		||||
    suc = cmd | getline to
 | 
			
		||||
    close(cmd)
 | 
			
		||||
    if (suc != 1) {
 | 
			
		||||
      exit 1
 | 
			
		||||
    }
 | 
			
		||||
    escape(summary);
 | 
			
		||||
    escape(desc);
 | 
			
		||||
  }
 | 
			
		||||
  escape(summary);
 | 
			
		||||
  escape(desc);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
NR == FNR && desc { desc = desc "\\n" $0; next; }
 | 
			
		||||
NR == FNR {
 | 
			
		||||
  from = substr($0, 1, 6) == "::: |>" ? substr($0, 8) : "";
 | 
			
		||||
  if (!from)
 | 
			
		||||
    exit 1
 | 
			
		||||
  getline
 | 
			
		||||
  to = substr($0, 1, 6) == "::: <|" ? substr($0, 8) : "";
 | 
			
		||||
  if (!to)
 | 
			
		||||
    exit 1
 | 
			
		||||
  getline
 | 
			
		||||
  summary = substr($0, 1, 2) == "# " ? substr($0, 3) : ""
 | 
			
		||||
  if (!summary)
 | 
			
		||||
    exit 1
 | 
			
		||||
  getline # This line should be empty
 | 
			
		||||
  getline # First line of description
 | 
			
		||||
  desc = $0;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										26
									
								
								src/main.sh
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								src/main.sh
									
									
									
									
									
								
							@@ -298,19 +298,24 @@ __edit() {
 | 
			
		||||
  # Update only if changes are detected
 | 
			
		||||
  if [ "$checksum" != "$(cksum "$filetmp")" ]; then
 | 
			
		||||
    filenew="$filetmp.ics"
 | 
			
		||||
    awk "$AWK_UPDATE" "$filetmp" "$fpath" >"$filenew"
 | 
			
		||||
    mv "$filenew" "$fpath"
 | 
			
		||||
    __refresh_data
 | 
			
		||||
    if awk "$AWK_UPDATE" "$filetmp" "$fpath" >"$filenew"; then
 | 
			
		||||
      mv "$filenew" "$fpath"
 | 
			
		||||
      __refresh_data
 | 
			
		||||
    else
 | 
			
		||||
      rm -f "$filenew"
 | 
			
		||||
      err "Failed to edit entry. Press <enter> to continue."
 | 
			
		||||
      read -r tmp
 | 
			
		||||
    fi
 | 
			
		||||
  fi
 | 
			
		||||
  rm "$filetmp"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
__refresh_data() {
 | 
			
		||||
  if [ -n "${APPROX_DATA_FILE:-}" ]; then
 | 
			
		||||
    rm "$APPROX_DATA_FILE"
 | 
			
		||||
    rm -f "$APPROX_DATA_FILE"
 | 
			
		||||
  fi
 | 
			
		||||
  if [ -n "${WEEKLY_DATA_FILE:-}" ]; then
 | 
			
		||||
    rm "$WEEKLY_DATA_FILE"
 | 
			
		||||
    rm -f "$WEEKLY_DATA_FILE"
 | 
			
		||||
  fi
 | 
			
		||||
  APPROX_DATA_FILE=$(mktemp)
 | 
			
		||||
  __load_approx_data >"$APPROX_DATA_FILE"
 | 
			
		||||
@@ -380,9 +385,14 @@ if [ "${1:-}" = "--new" ]; then
 | 
			
		||||
  # Update only if changes are detected
 | 
			
		||||
  if [ "$checksum" != "$(cksum "$filetmp")" ]; then
 | 
			
		||||
    filenew="$filetmp.ics"
 | 
			
		||||
    awk -v uid="$uuid" "$AWK_NEW" "$filetmp" >"$filenew"
 | 
			
		||||
    mv "$filenew" "$fpath"
 | 
			
		||||
    __refresh_data
 | 
			
		||||
    if awk -v uid="$uuid" "$AWK_NEW" "$filetmp" >"$filenew"; then
 | 
			
		||||
      mv "$filenew" "$fpath"
 | 
			
		||||
      __refresh_data
 | 
			
		||||
    else
 | 
			
		||||
      rm -f "$filenew"
 | 
			
		||||
      err "Failed to create new entry. Press <enter> to continue."
 | 
			
		||||
      read -r tmp
 | 
			
		||||
    fi
 | 
			
		||||
  fi
 | 
			
		||||
  rm "$filetmp"
 | 
			
		||||
fi
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user