Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 3, 2025

Problem

When a link name contained a comma, the CSV export would not properly escape it, causing the import to incorrectly split the name across multiple columns.

For example, a link with name "My Favorite Sites, Part 1" would be exported as:

https://example.com,1234567890,5,My Favorite Sites, Part 1

This would be incorrectly parsed as 6 columns instead of 4, with the name split into "My Favorite Sites" and " Part 1", resulting in data loss during import.

Solution

Export Fix (ExportRepositoryImpl.kt)

Replaced manual string interpolation with OpenCSV's CSVWriter API, which automatically handles proper escaping of commas, quotes, and newlines according to RFC 4180 standards:

Before:

val row = "${item.link},${item.createdAt},${item.openedCount},${item.name}\n"
writer.write(row)

After:

CSVWriter(writer).use { csvWriter ->
    csvWriter.writeNext(arrayOf(item.link, item.createdAt.toString(), 
                                 item.openedCount.toString(), item.name))
}

Import Fix (ImportRepositoryImpl.kt)

Updated the import logic to properly handle the NAME column and support both new properly-escaped CSVs and legacy improperly-formatted ones:

Before:

if (row.size >= 3) {
    val name = row[3].toString()

After:

if (row.size >= 4) {
    val name = row.drop(3).joinToString(",")

This approach:

  • Validates that all 4 expected columns (Link, CreatedAt, OpenedCount, Name) are present
  • Extracts everything from column 3 onwards as the name, joining with commas if needed
  • Handles both new CSVs (where name is properly in column 3) and legacy CSVs (where names with commas may be split)

Testing

Added comprehensive unit tests (CsvExportImportTest.kt) that verify:

  • Commas in values are properly escaped and parsed
  • Quotes in values are properly escaped
  • Newlines in values are properly handled
  • Multiple commas in a single name work correctly
  • The import join logic works for various scenarios

Result

With these changes, a link with name "My Favorite Sites, Part 1" will now be correctly exported as:

https://example.com,1234567890,5,"My Favorite Sites, Part 1"

And correctly imported with the full name intact.

Compatibility

Forward Compatibility: New CSV exports are properly formatted with RFC 4180 compliant escaping
Backward Compatibility: Import can still read old improperly formatted CSV files by joining split name columns

Fixes the issue where commas in link names caused data corruption during CSV export/import.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.google.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.13-bin/5xuhj0ry160q40clulazy9h7d/gradle-8.13/lib/gradle-daemon-main-8.13.jar -javaagent:/home/REDACTED/.gradle/wrapper/dists/gradle-8.13-bin/5xuhj0ry160q40clulazy9h7d/gradle-8.13/lib/agents/gradle-instrumentation-agent-8.13.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 8.13 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>If the name of the link contains a comma, when importing the csv it doesn't write it fully</issue_title>
<issue_description>If possible since the name is the last object of a deeplink when it gets exported, you can consider the title being whatever it's written after the 3rd comma to the last character of the line</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #120

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@Copilot Copilot AI changed the title [WIP] If the name of the link contains a comma, when importing the csv it doesn't write it fully Fix CSV import/export to properly handle commas in link names Oct 3, 2025
@Copilot Copilot AI requested a review from yogeshpaliyal October 3, 2025 15:54
Copilot finished work on behalf of yogeshpaliyal October 3, 2025 15:54
@ALE-ARME ALE-ARME mentioned this pull request Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

If the name of the link contains a comma, when importing the csv it doesn't write it fully
2 participants