Skip to content

Issue generating annotations when a column comment has newline character #778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tmr08c opened this issue Mar 22, 2020 · 0 comments · Fixed by #779
Closed

Issue generating annotations when a column comment has newline character #778

tmr08c opened this issue Mar 22, 2020 · 0 comments · Fixed by #779

Comments

@tmr08c
Copy link
Contributor

tmr08c commented Mar 22, 2020

When annotating a model with a column that had a comment that includes a newline character, the annotation will interpolate the newline character and add a non-commented line.

For example:

# schema.rb
  create_table "users", force: :cascade do |t|
    t.string "name", comment: "This is a comment.\nWith two lines!"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
  end

will generate the following annotation:

# user.rb

# == Schema Information
#
# Table name: users
#
#  id                                       :bigint           not null, primary key
#  name(This is a comment.
With two lines!) :string
#  created_at                               :datetime         not null
#  updated_at                               :datetime         not null
#

Commands

$ annotate --models --with-comment

Version

  • annotate version: 3.1.0
  • rails version: 6.0.2.2
  • ruby version: 2.6.5
@drwl drwl closed this as completed in #779 Apr 5, 2020
drwl pushed a commit that referenced this issue Apr 5, 2020
Closes #778 

If a column comment includes the newline character, the newline character
would be "printed" into the annotation block resulting in a line break
and an uncommented line.

For example, for the following table:

```
create_table "users", force: :cascade do |t|
  t.string "name", comment: "This is a comment.\nWith two lines!"
  t.datetime "created_at", precision: 6, null: false
  t.datetime "updated_at", precision: 6, null: false
end
```

annotating the model with the `--with-comment` flag will result in:

```
\# == Schema Information
\#
\# Table name: users
\#
\#  id                                       :bigint           not null, primary key
\#  name(This is a comment.
With two lines!) :string
\#  created_at                               :datetime         not null
\#  updated_at                               :datetime         not null
\#
```

This uncommented line would result in invalid Ruby and cause the file to
no longer be valid.

This fix replaces the newline character with an escaped version, so the
output will look more like:

```
\# == Schema Information
\#
\# Table name: users
\#
\#  id                                       :bigint           not null, primary key
\#  name(This is a comment.\nWith two lines!):string
\#  created_at                               :datetime         not null
\#  updated_at                               :datetime         not null
\#
```
vfonic pushed a commit to vfonic/annotate_models that referenced this issue May 8, 2020
Closes ctran#778 

If a column comment includes the newline character, the newline character
would be "printed" into the annotation block resulting in a line break
and an uncommented line.

For example, for the following table:

```
create_table "users", force: :cascade do |t|
  t.string "name", comment: "This is a comment.\nWith two lines!"
  t.datetime "created_at", precision: 6, null: false
  t.datetime "updated_at", precision: 6, null: false
end
```

annotating the model with the `--with-comment` flag will result in:

```
\# == Schema Information
\#
\# Table name: users
\#
\#  id                                       :bigint           not null, primary key
\#  name(This is a comment.
With two lines!) :string
\#  created_at                               :datetime         not null
\#  updated_at                               :datetime         not null
\#
```

This uncommented line would result in invalid Ruby and cause the file to
no longer be valid.

This fix replaces the newline character with an escaped version, so the
output will look more like:

```
\# == Schema Information
\#
\# Table name: users
\#
\#  id                                       :bigint           not null, primary key
\#  name(This is a comment.\nWith two lines!):string
\#  created_at                               :datetime         not null
\#  updated_at                               :datetime         not null
\#
```
ocarta-l pushed a commit to ocarta-l/annotate_models that referenced this issue Jun 18, 2021
Closes ctran#778 

If a column comment includes the newline character, the newline character
would be "printed" into the annotation block resulting in a line break
and an uncommented line.

For example, for the following table:

```
create_table "users", force: :cascade do |t|
  t.string "name", comment: "This is a comment.\nWith two lines!"
  t.datetime "created_at", precision: 6, null: false
  t.datetime "updated_at", precision: 6, null: false
end
```

annotating the model with the `--with-comment` flag will result in:

```
\# == Schema Information
\#
\# Table name: users
\#
\#  id                                       :bigint           not null, primary key
\#  name(This is a comment.
With two lines!) :string
\#  created_at                               :datetime         not null
\#  updated_at                               :datetime         not null
\#
```

This uncommented line would result in invalid Ruby and cause the file to
no longer be valid.

This fix replaces the newline character with an escaped version, so the
output will look more like:

```
\# == Schema Information
\#
\# Table name: users
\#
\#  id                                       :bigint           not null, primary key
\#  name(This is a comment.\nWith two lines!):string
\#  created_at                               :datetime         not null
\#  updated_at                               :datetime         not null
\#
```
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 a pull request may close this issue.

1 participant