bugfix: escaping, again
This commit is contained in:
@@ -1,16 +1,28 @@
|
|||||||
# unescape
|
# unescape
|
||||||
# Isolate and unescape the content part of an iCalendar line.
|
# Isolate and unescape the content part of an iCalendar line.
|
||||||
#
|
#
|
||||||
# @local variables: tmp
|
# @local variables: i, c, c2, res
|
||||||
# @input str: String
|
# @input str: String
|
||||||
# @return: Unescaped string
|
# @return: Unescaped string
|
||||||
function unescape(str) {
|
function unescape(str, i, c, c2, res) {
|
||||||
gsub("\\\\n", "\n", str)
|
for(i=1; i<=length(str);i++) {
|
||||||
gsub("\\\\N", "\n", str)
|
c = substr(str, i, 1)
|
||||||
gsub("\\\\,", ",", str)
|
if (c != "\\") {
|
||||||
gsub("\\\\;", ";", str)
|
res = res c
|
||||||
gsub("\\\\\\\\", "\\", str)
|
continue
|
||||||
return str
|
}
|
||||||
|
i++
|
||||||
|
c2 = substr(str, i, 1)
|
||||||
|
if (c2 == "n" || c2 == "N") {
|
||||||
|
res = res "\n"
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
# Alternatively, c2 is "\\" or "," or ";". In each case, append res with
|
||||||
|
# c2. If the strings has been escaped correctly, then the character c2
|
||||||
|
# cannot be anything else. To be fail-safe, simply append res with c2.
|
||||||
|
res = res c2
|
||||||
|
}
|
||||||
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
# getcontent
|
# getcontent
|
||||||
|
|||||||
@@ -1,16 +1,28 @@
|
|||||||
# unescape
|
# unescape
|
||||||
# Isolate and unescape the content part of an iCalendar line.
|
# Isolate and unescape the content part of an iCalendar line.
|
||||||
#
|
#
|
||||||
# @local variables: tmp
|
# @local variables: i, c, c2, res
|
||||||
# @input str: String
|
# @input str: String
|
||||||
# @return: Unescaped string
|
# @return: Unescaped string
|
||||||
function unescape(str) {
|
function unescape(str, i, c, c2, res) {
|
||||||
gsub("\\\\n", "\n", str)
|
for(i=1; i<=length(str);i++) {
|
||||||
gsub("\\\\N", "\n", str)
|
c = substr(str, i, 1)
|
||||||
gsub("\\\\,", ",", str)
|
if (c != "\\") {
|
||||||
gsub("\\\\;", ";", str)
|
res = res c
|
||||||
gsub("\\\\\\\\", "\\", str)
|
continue
|
||||||
return str
|
}
|
||||||
|
i++
|
||||||
|
c2 = substr(str, i, 1)
|
||||||
|
if (c2 == "n" || c2 == "N") {
|
||||||
|
res = res "\n"
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
# Alternatively, c2 is "\\" or "," or ";". In each case, append res with
|
||||||
|
# c2. If the strings has been escaped correctly, then the character c2
|
||||||
|
# cannot be anything else. To be fail-safe, simply append res with c2.
|
||||||
|
res = res c2
|
||||||
|
}
|
||||||
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
# getcontent
|
# getcontent
|
||||||
|
|||||||
@@ -14,16 +14,28 @@ function singleline(str) {
|
|||||||
|
|
||||||
# Isolate and unescape the content part of an iCalendar line.
|
# Isolate and unescape the content part of an iCalendar line.
|
||||||
#
|
#
|
||||||
# @local variables: tmp
|
# @local variables: i, c, c2, res
|
||||||
# @input str: String
|
# @input str: String
|
||||||
# @return: Unescaped string
|
# @return: Unescaped string
|
||||||
function unescape(str) {
|
function unescape(str, i, c, c2, res) {
|
||||||
gsub("\\\\n", "\n", str)
|
for(i=1; i<=length(str);i++) {
|
||||||
gsub("\\\\N", "\n", str)
|
c = substr(str, i, 1)
|
||||||
gsub("\\\\,", ",", str)
|
if (c != "\\") {
|
||||||
gsub("\\\\;", ";", str)
|
res = res c
|
||||||
gsub("\\\\\\\\", "\\", str)
|
continue
|
||||||
return str
|
}
|
||||||
|
i++
|
||||||
|
c2 = substr(str, i, 1)
|
||||||
|
if (c2 == "n" || c2 == "N") {
|
||||||
|
res = res "\n"
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
# Alternatively, c2 is "\\" or "," or ";". In each case, append res with
|
||||||
|
# c2. If the strings has been escaped correctly, then the character c2
|
||||||
|
# cannot be anything else. To be fail-safe, simply append res with c2.
|
||||||
|
res = res c2
|
||||||
|
}
|
||||||
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
# Isolate content part of an iCalendar line, and unescape.
|
# Isolate content part of an iCalendar line, and unescape.
|
||||||
@@ -194,8 +206,7 @@ ENDFILE {
|
|||||||
if (type == "VTODO")
|
if (type == "VTODO")
|
||||||
{
|
{
|
||||||
# Either DUE or DURATION may appear. If DURATION appears, then also DTSTART
|
# Either DUE or DURATION may appear. If DURATION appears, then also DTSTART
|
||||||
d = due ? due :
|
d = due ? due : (dur ? dts " for " dur : "");
|
||||||
(dur ? dts " for " dur : "");
|
|
||||||
if (d && d <= today && sta != "COMPLETED")
|
if (d && d <= today && sta != "COMPLETED")
|
||||||
{
|
{
|
||||||
datecolor = RED;
|
datecolor = RED;
|
||||||
|
|||||||
@@ -4,9 +4,9 @@
|
|||||||
# @return: Escaped string
|
# @return: Escaped string
|
||||||
function escape(str)
|
function escape(str)
|
||||||
{
|
{
|
||||||
gsub("\\\\", "\\", str)
|
gsub("\\\\", "\\\\", str)
|
||||||
gsub(";", "\\;", str)
|
gsub(";", "\\;", str)
|
||||||
gsub(",", "\\,", str)
|
gsub(",", "\\,", str)
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -16,8 +16,8 @@ function escape(str)
|
|||||||
# @return: Escaped string
|
# @return: Escaped string
|
||||||
function escape_categories(str)
|
function escape_categories(str)
|
||||||
{
|
{
|
||||||
gsub("\\\\", "\\", str)
|
gsub("\\\\", "\\\\", str)
|
||||||
gsub(";", "\\;", str)
|
gsub(";", "\\;", str)
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ BEGIN {
|
|||||||
type = "VJOURNAL";
|
type = "VJOURNAL";
|
||||||
zulu = strftime("%Y%m%dT%H%M%SZ", systime(), 1);
|
zulu = strftime("%Y%m%dT%H%M%SZ", systime(), 1);
|
||||||
}
|
}
|
||||||
desc { desc = desc "\\n" $0; next; }
|
desc { desc = desc "\\n" escape($0); next; }
|
||||||
{
|
{
|
||||||
if (substr($0, 1, 6) == "::: |>")
|
if (substr($0, 1, 6) == "::: |>")
|
||||||
{
|
{
|
||||||
@@ -60,12 +60,12 @@ desc { desc = desc "\\n" $0; next; }
|
|||||||
due = substr($0, 8);
|
due = substr($0, 8);
|
||||||
getline;
|
getline;
|
||||||
}
|
}
|
||||||
summary = substr($0, 1, 2) != "# " ? "" : substr($0, 3);
|
summary = substr($0, 1, 2) != "# " ? "" : escape(substr($0, 3));
|
||||||
getline;
|
getline;
|
||||||
categories = substr($0, 1, 1) != ">" ? "" : substr($0, 3);
|
categories = substr($0, 1, 1) != ">" ? "" : escape(substr($0, 3));
|
||||||
getline; # This line should be empty
|
getline; # This line should be empty
|
||||||
getline; # First line of description
|
getline; # First line of description
|
||||||
desc = $0;
|
desc = escape($0);
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
END {
|
END {
|
||||||
@@ -76,9 +76,6 @@ END {
|
|||||||
cmd | getline res
|
cmd | getline res
|
||||||
due = res ? res : ""
|
due = res ? res : ""
|
||||||
}
|
}
|
||||||
summary = escape(summary);
|
|
||||||
desc = escape(desc);
|
|
||||||
categories = escape_categories(categories);
|
|
||||||
|
|
||||||
# print ical
|
# print ical
|
||||||
print "BEGIN:VCALENDAR";
|
print "BEGIN:VCALENDAR";
|
||||||
|
|||||||
@@ -4,9 +4,9 @@
|
|||||||
# @return: Escaped string
|
# @return: Escaped string
|
||||||
function escape(str)
|
function escape(str)
|
||||||
{
|
{
|
||||||
gsub("\\\\", "\\", str)
|
gsub("\\\\", "\\\\", str)
|
||||||
gsub(";", "\\;", str)
|
gsub(";", "\\;", str)
|
||||||
gsub(",", "\\,", str)
|
gsub(",", "\\,", str)
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -16,8 +16,8 @@ function escape(str)
|
|||||||
# @return: Escaped string
|
# @return: Escaped string
|
||||||
function escape_categories(str)
|
function escape_categories(str)
|
||||||
{
|
{
|
||||||
gsub("\\\\", "\\", str)
|
gsub("\\\\", "\\\\", str)
|
||||||
gsub(";", "\\;", str)
|
gsub(";", "\\;", str)
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,25 +57,22 @@ ENDFILE {
|
|||||||
cmd | getline res
|
cmd | getline res
|
||||||
due = res ? res : ""
|
due = res ? res : ""
|
||||||
}
|
}
|
||||||
summary = escape(summary);
|
|
||||||
desc = escape(desc);
|
|
||||||
categories = escape_categories(categories);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NR == FNR && desc { desc = desc "\\n" $0; next; }
|
NR == FNR && desc { desc = desc "\\n" escape($0); next; }
|
||||||
NR == FNR {
|
NR == FNR {
|
||||||
if (substr($0, 1, 6) == "::: <|")
|
if (substr($0, 1, 6) == "::: <|")
|
||||||
{
|
{
|
||||||
due = substr($0, 8);
|
due = substr($0, 8);
|
||||||
getline;
|
getline;
|
||||||
}
|
}
|
||||||
summary = substr($0, 1, 2) != "# " ? "" : substr($0, 3);
|
summary = substr($0, 1, 2) != "# " ? "" : escape(substr($0, 3));
|
||||||
getline;
|
getline;
|
||||||
categories = substr($0, 1, 1) != ">" ? "" : substr($0, 3);
|
categories = substr($0, 1, 1) != ">" ? "" : escape_categories(substr($0, 3));
|
||||||
getline; # This line should be empty
|
getline; # This line should be empty
|
||||||
getline; # First line of description
|
getline; # First line of description
|
||||||
desc = $0;
|
desc = escape($0);
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -249,7 +249,7 @@ if [ "${1:-}" = "--no-journal" ]; then
|
|||||||
query="!📘"
|
query="!📘"
|
||||||
fi
|
fi
|
||||||
query=${query:-!✅}
|
query=${query:-!✅}
|
||||||
query=$(echo "$query" | xargs)
|
query=$(echo "$query" | sed "s/^ *//" | sed "s/ *$//")
|
||||||
|
|
||||||
selection=$(
|
selection=$(
|
||||||
__lines | $FZF --ansi \
|
__lines | $FZF --ansi \
|
||||||
|
|||||||
Reference in New Issue
Block a user